In article <e4**************************@posting.google.com >,
sl**********@yahoo.com enlightened us with...
Hi,
I'm writing a CGI application and here's what I'm stuck with. There
are some text boxes in an html form that I want to validate. The
validation needs to happen on the server side because the data to
validate against is inside a mysql database residing on the server. I
want to present the user with a popup only if the validation fails.
Ideally the user doesn't even know the validation is happening unless
it fails. He just moves from field to field. I know how to trap the
condition of the user moving out of a text field. I know how to invoke
a CGI script from javascript. What I don't know is how, if it's even
possible, to have the result of moving out of the text field trigger
code that either returns silently or opens a popup, depending on what
I find in my validation code.
Is this possible in Javascript? If not can someone recommend what
language I might be able to do this in?
Thanks,
SL
Tested in NN7. Should work in IE5+, too.
Modify it to suit. I'm not a big perl geek, so this is a really simple
test. ;)
Watch for word-wrap.
test.htm
----------------
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
"http://www.w3.org/TR/REC-html40/loose.dtd">
<html>
<head>
<title> Test server-side JS </title>
</head>
<body>
<script type="text/javascript">
function checkIt(variable, value)
{
var newScript = "cgi-bin/validateJS.cgi?"+variable+"="+value;
var body = document.getElementsByTagName('body').item(0)
var scriptTag = document.getElementById('loadScript');
if(scriptTag) body.removeChild(scriptTag);
script = document.createElement('script');
script.src = newScript;
script.type = 'text/javascript';
script.id = 'loadScript';
body.appendChild(script)
}
</script>
<p>Test.</p>
<form id="f1" action="">
<input type="text" name="t1" id="t1" onChange="checkIt(this.name,
this.value)">
</body>
</html>
validateJS.cgi (perl)
-------
#!/opt/x11r6/bin/perl
use CGI qw(:all);
my @valArray = split(/=/,$ENV{QUERY_STRING});
print "Content-type: text/javascript\n\n";
# myPass is the password
$myPass = "foobar";
if ("$valArray[1]" eq "$myPass")
{
print "alert(\"Success!!\")";
}
else
{
print "alert(\"Failure!!\")";
}
# end file
HTH
--
--
~kaeli~
No one is listening until you make a mistake.
http://www.ipwebdesign.net/wildAtHeart http://www.ipwebdesign.net/kaelisSpace