
Zhris
User
Apr 10, 2012, 12:38 PM
Post #5 of 6
(1069 views)
|
|
Re: [aurora] onClick event is not working in cgi
[In reply to]
|
Can't Post
|
|
Hi, - Your "complete code" does not make use of the code in your original post. - Running your code instantly produced a javascript error, which was the likely cause of your issue. - You can print blocks of HTML (see example below). - If you do want to use individual print statements, its probably best to use quote like operators e.g. q or qq. - For top marks, use a template module! - Your code makes no special use of Perl and as it stands would be more suitable in a html file. etc Here is my re-write of your code (your javascript was messy therefore I may have adapted it incorrectly):
#!/usr/bin/perl use strict; use warnings; use CGI; my $cgi = CGI->new(); print $cgi->header(); print <<"HTMLcode"; <html> <head> <script type="text/javascript"> function CheckForm_onclick() { var myForm = document.form1; var userid = myForm.userid.value; if (userid == "") { alert('Please enter your user id'); return false; } else { alert('Your user id is ' + userid); return true; } } </script> </head> <body> <form id="form1" name="form1"> <table> <tr> <td> User ID: <input type="text" name="userid" value="" size="7" /> <input type="Button" id="val" value="View" align="middle" onclick="CheckForm_onclick()" /> </td> </tr> </table> </form> </body> </html> HTMLcode 1; Chris
(This post was edited by Zhris on Apr 10, 2012, 12:40 PM)
|