469,643 Members | 2,064 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,643 developers. It's quick & easy.

Need help with conditional creation of a popup window

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
Jul 23 '05 #1
3 1720
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

--
William Morris
Product Development, Seritas LLC
Kansas City, Missouri

"Sol Linderstein" <sl**********@yahoo.com> wrote in message
news:e4**************************@posting.google.c om...
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

Jul 23 '05 #2
William Morris wrote:
<snip>
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.
Jul 23 '05 #3
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

Jul 23 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by James Hong | last post: by
16 posts views Thread by St. Rechsteiner | last post: by
2 posts views Thread by Mike Button | last post: by
1 post views Thread by David Cho | last post: by
3 posts views Thread by Chris | last post: by
5 posts views Thread by Chris | last post: by
11 posts views Thread by Alex.Svetos | last post: by
1 post views Thread by lawsongs | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.