Need help with conditional creation of a popup window

  • Thread starter Sol Linderstein
  • Start date
S

Sol Linderstein

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
 
W

William Morris

What you're wanting to do is probably more trouble than it's worth, since
the only way to cause anything to happen in a web environment is to submit a
page to some process somewhere. As an end user, I would say that it's
better to validate everything at once at the end, rather than interupting me
after every field where I make a mistake. As a programmer, I'd tell you
it's better to validate on the server since the end user can turn off
javascript.

Now, if you have control of your environment, as in an intranet application,
you can put an IFRAME on your page and submit your validations to that.
Communicate with the IFRAME by its id, and it communicates back by referring
to its parent.

Still better to validate on the server, though.

- Wm
 
R

Richard Cornford

William Morris wrote:
As a programmer, I'd tell you it's better to validate on
the server since the end user can turn off javascript.
<snip>

You make it sound like it is an either-or situation. Validating on the
server is essential because, as you say, the user can turn javascript
off. They can also subvert the javascript so it will allow any
submission at all, fake the form on a different page or fake the request
using non-browser software.

But that doesn't render client-side validation invalid as an additional
layer. For users who are not messing around and have javascript enabled,
if client side code can tell that a the server-side validation will
reject the form date then it doesn't seem unreasonable to let the user
know at that point and to not send the data to the server. It will
eliminate unnecessary requests to the server and save the user waiting
for a response that will just tell them that they need to correct the
form.

On the other hand, client-side validation that is done by making
background requests to the server doesn't seem to offer any advantages
over exclusively server-side validation, and it certainly introduces
considerable complexity and reliability issues.

Richard.
 
K

kaeli

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
--
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top