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

To begin with, I am just trying to display an alert box when a check box is selected. Here is the javascript code that I used

$JSCRIPT=<<END; <script language="text/javascript"> function selectAll() { alert('Hello'); } </script> END

Here is the checkbox

$cgi->checkbox ( -name=>'All', -onClick=>"selectAll()", ),

But nothing happens when I select the All checkbox. Your help will be really appreciated.

Replies are listed 'Best First'.
Re: Unable to use onClick with checkbox
by Corion (Patriarch) on Jul 25, 2012 at 07:26 UTC

    Have you looked at the generated HTML+Javascript output? Does it match what you expect? If it matches what you expect, the issue is on the client (browser) side, and we cannot help you there. If the generated output is not what you expect, please post the relevant parts to help us help you better.

      The cgi creates the form and the checkbox as expected. The java script is supposed to give an alert which it does not do. If I use $cgi->checkbox ( -name=>'All', -onClick=>"alert('Hello'", ), it works. What more information do you need?

        If the generated output is what you expect, why doesn't it work? Maybe your expectation is wrong? What is the generated output? Does the generated output work if you save it as a .html file and open that file locally?

        If the generated output is not what you expect, please post the relevant parts to help us help you better.

        Maybe you can now post the relevant parts of the script and the generated output to help us help you better? That would maybe let somebody see how your expectations do not match what a browser expects. I still recommend testing whether the generated output works as a static file, locally and/or served by the web server. If it doesn't work as a static file, the problem is in your Javascript and thus out of the realm of Perl. If it works as a static file but not when served via a CGI program, we need to see the code and the output.

        What more information do you need?

        None. Corion said: "If it matches what you expect, the issue is on the client (browser) side, and we cannot help you there."

        You will have to debug your own javascript, sorry.

Re: Unable to use onClick with checkbox
by Anonymous Monk on Jul 25, 2012 at 07:34 UTC