In article <ca**********@blsnews.bls.gov>,
ja********@bls.gov
enlightened us with...
Hi all,
I would appreciate it if anyone could point me on this.
My JSP page has 3 select boxes for states, counties and, cities and the
counties and cities should be populated once the user chooses a state and so
forth for the cities too.
I will need to get the data from an Oracle database.
Thanks so much in advance.
You can modify this javascript/CGI combo to instead have an onchange of
a select call a *servlet* (not a JSP page) that generates the
javascript. Note that this is merely an example of getting a client-side
event to trigger a server-side action. You need to make a javascript
that will change your options appropriately. I have an example of that
script, too, if you'd like.
This works only in DOM browsers and, for production, should be wrapped
in a check block to prevent bad things from happening on old browsers.
<!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
#!/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!!\")";
}
--
--
~kaeli~
God was my co-pilot... but then we crashed in the mountains
and I had to eat him.
http://www.ipwebdesign.net/wildAtHeart http://www.ipwebdesign.net/kaelisSpace