"lance" <pa***@sams-cycles.com> wrote in message
news:i%***************@fe2.texas.rr.com...
I need a javascript function that will decide a form action determined by
a form string.
For instance I want the javascript to set the form action to go to one
script when a code number is entered into a field
and I want it to default to another script when this code number is not
present.
I need to solution to this ASAP I am in the middle of a major project and
dont have time to handle this detail.
Dear Mr Stehling
1. This newsgroup is for Java, not Javascript. The two are
not the same.
2. As Javascript executes on the client (i.e. the browser), the
code is insecure - anyone can browse it. Hence this method is
unsuitable for any kind of sensitive information.
3. Clients cannot be guaranteed to have Javascript running -
about 10% of people don't, for one reason or another.
If #2 and #3 don't dissuade you, then the following may help:
<html>
<head>
<title>My Motorcycles</title>
<script language='JavaScript'>
<!--
function doCheck() {
secretCode = 12345;
txt = document.forms.f.myText.value;
if (parseInt(txt,10) == secretCode) {
top.location = 'secretpage.html';
return false;
}
else {
return true;
}
}
// -->
</script>
</head>
<body>
<form name='f' action='defaultpage.jsp' onsubmit='return doCheck();'>
<input name='myText' type='text' />
<input type='submit' />
</form>
</body>
</html>
This works with IE, I won't guarantee it on any other
browser; also, I think you would be better off using
server-side code.