I'm having a problem getting some javascript functions to execute inside a perl script. Basically I have a very simple form with some validation functions in javascript. The form worked fine, but once I turned it into a perl script, the javascript stopped working. Here's all the code.
#!/usr/bin/perl
print "Content-type: text/html\n\n";
use CGI qw(:standard);
use CGI::Carp qw(fatalsToBrowser);
use strict;
my($username,$password,$user,$pass);
$username = param("username");
$password = param("password");
$user = "smokejacks";
$pass = "running";
if($username eq $user and $password eq $pass)
{
print <<_HTML_;
<html>
<head>
<title>Participants Form</title>
<style>
td {font-family:verdana,arial;font-size:x-small}
body {font-family:verdana,arial;font-size:x-small}
</style>
<script language="Javascript">
<!--
function MM_findObj(n, d) { //v4.0
var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
if(!x && document.getElementById) x=document.getElementById(n); return x;
}
function MM_validateForm() { //v4.0
var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
if (val) { nm=val.name; if ((val=val.value)!="") {
if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
} else if (test!='R') {
if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
min=test.substring(8,p); max=test.substring(p+1);
if (val<min || max<val) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
} } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
} if (errors) alert('The following error(s) occurred:\n'+errors);
document.MM_returnValue = (errors == '');
}
//-->
</script>
</head>
<body bgcolor="white" onload="self.focus();document.reg.firstname.focus()">
<form name=reg action="participantListOut.cgi" method="post" onsubmit="MM_validateForm('firstname','','R','lastname','','R','age','','R','Location','','R','email','','RisEmail');return document.MM_returnValue">
Enter the following information:<br>
<br><br>
<table>
<tr><td>First Name:</td><td><input type=text name=firstname size=25></td></tr>
<tr><td>Last Name:</td><td><input type=text name=lastname size=25></td></tr>
<tr><td>Age:</td><td><input type=text name=age size=2></td></tr>
<tr><td>Location:</td><td><input type=text name=Location size=25></td></tr>
<tr><td>Email:</td><td><input name=email size=25></td></tr>
<tr><td></td><td><br><input type="submit" value="Submit"> <input type="reset" value="Reset"></td></tr>
</table>
</form>
_HTML_
}
else
{
print "<br> Sorry, log-in failed<br><br>";
print "<form name=username action=participantForm.cgi>";
print " Username <br> <input name=username size=15><br>";
print " Password<br> <input type=password name=password size=15><br><br>";
print " <input type=submit value=Submit> <input type=reset value=Reset>";
print "</form>";
}
print <<_HTML2_;
</body>
</html>
_HTML2_
Javascript Embedded In Perl Won't Workjavascript disabled
Page 1 of 1
5 Replies - 5870 Views - Last Post: 06 May 2003 - 04:04 PM
Replies To: Javascript Embedded In Perl Won't Work
#2
Re: Javascript Embedded In Perl Won't Work
Posted 05 May 2003 - 08:50 PM
does the javascript show up properly in the finished source code??
#3
Re: Javascript Embedded In Perl Won't Work
Posted 06 May 2003 - 09:58 AM
thanks for replying. when I view source, the javascript is in there.
#4
Re: Javascript Embedded In Perl Won't Work
Posted 06 May 2003 - 02:28 PM
triple-check that the *finished* javascript, coming through the source, says exactly what it needs to. it's possible that in the conversion you lost something... are you getting an error message? what's it doing?
#5
Re: Javascript Embedded In Perl Won't Work
Posted 06 May 2003 - 03:55 PM
I found the problem. Very subtle. I had to place a string literal slash before a "@" symbol, because perl probably thought I was declaring an array. Thanks for replying.
#6
Re: Javascript Embedded In Perl Won't Work
Posted 06 May 2003 - 04:04 PM
This is a feature of the latest version of Perl -- older versions would allow an un-commented @. And, since you were using a CGI wrapper you woulnd't see the typical command line warning about this.
Sneaky.
Sneaky.
Page 1 of 1
|
|

New Topic/Question
Reply


MultiQuote




|