tarunkhanna has asked for the wisdom of the Perl Monks concerning the following question:
I am running the below code.
In the above code, alert box doesn't appear on clicking submit button with or without any value in "name" text box.use CGI; my $co = new CGI; use CGI qw(:standard); use CGI::Carp qw(fatalsToBrowser); use strict; use diagnostics; print $co->header; print $co->start_html(); print $co->start_form; print $co->h4("Name").$co->p; print $co->textfield('name').$co->p; print <<CheckNameBox; <script language="JavaScript"> function CheckForEmptyTextbox() { alert(document.getElementById("name").value); } // end function </script> CheckNameBox print $co->submit(-onclick=>"CheckForEmptyTextbox()"); print $co->reset; print $co->end_form; print $co->end_html;
use CGI; my $co = new CGI; use CGI qw(:standard); use CGI::Carp qw(fatalsToBrowser); use strict; use diagnostics; print $co->header; print $co->start_html(); print $co->start_form; print $co->h4("Name").$co->p; print $co->textfield('name').$co->p; print <<CheckNameBox; <script language="JavaScript"> function CheckForEmptyTextbox() { alert("hello"); } // end function </script> CheckNameBox print $co->submit(-onclick=>"CheckForEmptyTextbox()"); print $co->reset; print $co->end_form; print $co->end_html;
But in the 2nd code, alert box appears. May be in the 1st code, document.getElementById("name").value is not able to pick the value from textbox. Why alert box not appearing in the first code or what steps shall i take to make alert box working in the first code with the value in name textbox.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Javascript with CGI
by marto (Cardinal) on Oct 07, 2011 at 08:27 UTC | |
|
Re: Javascript with CGI
by Anonymous Monk on Oct 07, 2011 at 06:30 UTC | |
|