Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

How a HTML radio button on click calls a CGI function?

by sanjay nayak (Sexton)
on Dec 17, 2008 at 09:31 UTC ( [id://730872]=perlquestion: print w/replies, xml ) Need Help??

sanjay nayak has asked for the wisdom of the Perl Monks concerning the following question:


Hi Monks
#!C:\Perl\bin\perl.exe -w use CGI; my $cgi = CGI->new; print $cgi->header( "text/html" ); print "<textarea name='txtOutput' value = 'txtOutput' style='width: 25 +0px'></textarea>"; print "<input type='radio' name='cbox' value='alice' selected onClick += 'char_value()'/>Char Value"; print "<input type='radio' name='cbox' value='' onClick= '32bits_valu +e()'/>32bits value";

Plz suggest me a suitable code so that when i click on the 32bits value radio button it will call the subroutine 32bits_value() by passing the value present in the text area as argument, there it will do some conversions and the converted value is automatically shown in the text area.

Like that when i will click on the Char value radio button, it will call the subroutine char_value() by passing the value present in the text area as argument, there again it will do some conversion and the converted value is automatically shown in the text area.

Regd's
Sanjay

Replies are listed 'Best First'.
Re: How a HTML radio button on click calls a CGI function?
by Corion (Patriarch) on Dec 17, 2008 at 09:57 UTC
Re: How a HTML radio button on click calls a CGI function?
by Erez (Priest) on Dec 17, 2008 at 11:22 UTC

    Plz suggest me a suitable code so that when i click on the 32bits value radio button it will call the subroutine 32bits_value()

    You need to make a distinction here. While clicking on the radio button is a client-side event, the actual function lies on the server.
    In order for a client-side event to trigger a server action, you need to send a request to the server (aka Postback request). There are several ways of doing that, from reloading the whole page, to a specific AJAX call (which won't load the whole page).

    However, If I'm reading your question right, there shouldn't be any actual call to the server, since you can run the calculations client-side via JavaScript.

    "A core tenant of the greater Perl philosophy is to trust that the developer knows enough to solve the problem" - Jay Shirley, A case for Catalyst.


      Hi
      Thanks for the reply.
      #!C:\Perl\bin\perl.exe -w use strict; use CGI; # or any other CGI:: form handler/decoder use CGI::Ajax; my $cgi = new CGI; my $pjx = new CGI::Ajax( 'exported_func' => \&perl_func ); print $pjx->build_html( $cgi, \&Show_HTML); sub perl_func { my $input = shift; # do something with $input my $output = $input . " was the input!"; return( $output ); } sub Show_HTML { my $html = <<EOHTML; <HTML> <BODY> Enter something: <input type="text" name="val1" id="val1" onkeyup="exported_func( ['val1'], ['resultdiv'] );"> <br> <div id="resultdiv"></div> </BODY> </HTML> EOHTML return $html; }

      When i want to compile this code , it gives a error "Can't find string terminator "EOHTML" anywhere before EOF at ajay.pl line 19.". Plz suggest why this error comes?

      Regd's
      Sanjay

        You probably have whitespace in front of the EOHTML string terminator. Delete anything (tabs, spaces) before it, or better yet, use the CGI methods to generate the html for you.

        "A core tenant of the greater Perl philosophy is to trust that the developer knows enough to solve the problem" - Jay Shirley, A case for Catalyst.

Re: How a HTML radio button on click calls a CGI function?
by matrixmadhan (Beadle) on Dec 17, 2008 at 11:02 UTC
    Am not replying to the question you have asked, just adding a suggestion to the code snippet you had posted
    There are functions in cgi that does this, for ex:textarea
    Here is a sample how you could do that
    $cgi>textarea( -name => $box_name, -rows => $no_of_rows, -maxlength => $max_length, -cols => $no_of_cols );

    instead of using print statements to print html code directly
    this is more readable and maintainable
Re: How a HTML radio button on click calls a CGI function?
by bradcathey (Prior) on Dec 17, 2008 at 13:27 UTC

    So, we're talking Javascript here. Right?

    I'd give and id to the textarea and use that in my event call:

    print "<textarea name='txtOutput' id='txtOutput' value='txtOutput' sty +le='width: 250px'></textarea>"; print "<input type='radio' name='cbox' value='alice' selected onClick +='char_value()'/>Char Value"; print "<input type='radio' name='cbox' value='' onClick= '32bits_value +(document.getElementById(\'txtOutput\').value)'/>32bits value";

    Untested.

    —Brad
    "The important work of moving the world forward does not wait to be done by perfect men." George Eliot

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://730872]
Approved by Hue-Bond
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (2)
As of 2024-03-19 06:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found