CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
onClick event is not working in cgi

 



aurora
Novice

Apr 5, 2012, 1:23 AM

Post #1 of 6 (1840 views)
onClick event is not working in cgi Can't Post

hi,
I used a button onClick in cgi as shown below....

Code
$q->button(-name=>'add_details',-id=>"button_id",-value=>"button_val",-onClick=>"Update_database()"));


but its not working as expected....nothing will happen if i click on the button....
Please help me what changes i nee to do for my cgi prg?


Zhris
Enthusiast

Apr 5, 2012, 1:28 PM

Post #2 of 6 (1818 views)
Re: [aurora] onClick event is not working in cgi [In reply to] Can't Post

Hi,

You haven't provided enough info / code to provide a definitive solution. The only problem I can see with the code you provided is the extra closing parenthesis on the end, which should be reported as a syntax error (could be where you copied and pasted though). My guess is that the Update_database javascript function isn't working correctly.

Chris


(This post was edited by Zhris on Apr 5, 2012, 1:29 PM)


wickedxter
User

Apr 7, 2012, 12:06 PM

Post #3 of 6 (1751 views)
Re: [aurora] onClick event is not working in cgi [In reply to] Can't Post

from what if read the -OnClick is for javascript calls
http://cpansearch.perl.org/src/LDS/CGI.pm-3.43/cgi_docs.html


aurora
Novice

Apr 9, 2012, 9:23 PM

Post #4 of 6 (1712 views)
Re: [Zhris] onClick event is not working in cgi [In reply to] Can't Post

my complete code is:


Code
#!/usr/bin/perl 
use strict;
use warnings;
use CGI;
my $cgi = CGI->new();
print STDOUT "Content-type: text/html\n\n";
print "<html>\n";
print "<head>\n";
print "<script type='text/javascript'>\n";
print "function CheckForm_onclick() \n";
print "{\n";
print "var myForm = document.form1;//document.getElementById(\"form1\")";
print "var message = \"\"";
print "alert(1)";
print "if (myForm.userid.value == \"\") {";
print "alert(1)\n";
print "message = \"Please enter your user id.\"\n";
print "}\n";
print "alert(message)\n";
print "if (message != \"\") {\n";
print "alert(message)\n";
print "return(false)\n";
print "}\n";
print "else {\n";
print "return(true)\n";
print "}\n";
print "}\n";
print "</script> \n";

print "<title>Ticket Purchases for Special Events</title>";
print "</head>";
print "<body>";
print "<form id=\"form1\" name=\"form1\" >";
print "<table><td><p>User ID: <input type=\"text\" name=\"userid\" value=\"\" size=\"7\">";
print "<input type='Button' id='val' value='View' align='middle' onclick=\"CheckForm_onclick()\" ></p></td></table></form>";
print "</body>";
print "</html>";



Zhris
Enthusiast

Apr 10, 2012, 12:38 PM

Post #5 of 6 (1681 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):


Code
#!/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)


aurora
Novice

Apr 16, 2012, 12:11 AM

Post #6 of 6 (1600 views)
Re: [Zhris] onClick event is not working in cgi [In reply to] Can't Post

Thank u for ur reply...:)Smile

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives