firstly apologies
A. this is a perl/javascript question
B. Im a perl newbie (ish)
C Im a javascript novice
D. I'm doing somthing stupid!
what's wrong with the code below ??
the function runs (i see the first alert) but in firebug, the next js section causes a "checkbox_form is not defined" and i dont see the alert when no check box's are ticked.
#!/usr/bin/perl
use CGI qw(:standard);
use CGI::Carp qw(fatalsToBrowser);
$JSCRIPT=<<EOF;
function validate() {
alert(" yes it ran");
var checkbox_choices = 0;
// Loop from zero to the one minus the number of checkbox button selec
+tions
for (counter = 0; counter < checkbox_form.checkbox.length; counter++)
{
// If a checkbox has been selected it will return true
// (If not it will return false)
if (checkbox_form.checkbox[counter].checked)
{ checkbox_choices = checkbox_choices + 1; }
}
if (checkbox_choices < 1 )
{
// If there were less then selections made display an alert box
alert("Please make a selection");
return (false);
}
};
EOF
;
print header;
print start_html(-script=>$JSCRIPT);
print h1("this is the main");
print start_form(-action=>"/cgi-bin/mockup/main2.cgi",
-target=>"mainframe",
-name=>"checkbox_form",
-onSubmit=>"return validate()"),
checkbox_group(-name=>"checkbox",
-values=>['red','green','blue']),
p(),submit;
print end_form;
print end_html;
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.