Above CGI code is calling CheckForEmptyTextbox() function in javascript. But this javascript is in the different file.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(-method => "POST", -action => 'first.cgi'); print $co->h4("Name").$co->p; print $co->textfield({name => 'name', id => 'name'}).$co->p; print $co->submit(-onclick=>"return CheckForEmptyTextbox()"); print $co->reset; print $co->end_form; print $co->end_html;
Javascript
How to call above javascript function from CGI program which is in different files??print <<CheckNameBox; <script language="JavaScript"> function CheckForEmptyTextbox() { if(document.getElementById("name").value=="") { alert ("Emtpy"); return false; } return true; } // end function </script> CheckNameBox
If I paste the above javascript code in the same CGI file, it works.
But what if I want javascript code to be in different file??In reply to (OT) Javascript with CGI using different files by tarunkhanna
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |