javascript - How to call an onclick function from a radio button when it is changed dynamically? -


i'm working cgi file , gets below parameter query string , uses shown below.

$rettype = p->param('rettype'); if($rettype eq "a") { $achecked="checked"; $rchecked=""; } if($rettype eq "r") { $achecked=""; $rchecked="checked"; } 

this used in later portion of file chooses radio button needs selected.

<input type="radio" name="gctyp" value="a" $achecked onclick="showtextarea()";>add <input type="radio" name="gctyp" value="r" $rchecked onclick="hidetextarea()";>remove 

now, want onclick js function present in radio button called based on option checked. happens dynamically , function isn't getting called.

thanks help

seems executing perl code , printing direct html output. that's known hardcoded html , not practice. templating modules template::toolkit better results , cleaner code. also, own good, hope using use strict , use warnings @ top of perl code.

also, html tags written in uppercase. that's deprecated, use lowercase tags , parameters, , add / before closing tags don't have closing tag, input case.

that being said, example of how solve mentioned:

my $javascript_call;  $rettype = p->param('rettype'); if ($rettype eq "a") {     $achecked = "checked";     $rchecked = "";     $javascript_call = 'showtextarea()'; } if ($rettype eq "r") {     $achecked = "";     $rchecked = "checked";     $javascript_call = 'hidetextarea()'; }  print <<end;     <input type="radio" name="gctyp" value="a" $achecked onclick="showtextarea()" />add     <input type="radio" name="gctyp" value="r" $rchecked onclick="hidetextarea()" />remove     <script type="text/javascript">         $javascript_call     </script> end 

i'm adding variable containing call executed after printing radio buttons , using same code structure presented that.

hth


Comments

Popular posts from this blog

database - VFP Grid + SQL server 2008 - grid not showing correctly -

jquery - Set jPicker field to empty value -

.htaccess - htaccess convert request to clean url and add slash at the end of the url -