Second form validation problem

J

John

Hi

I have two forms on my page. Both use javascript to validate input before
submission. Problem is that first form does the validation fine but the
second form gets submitted without any validation taking place. Simplified
form of code is given below.

What am I doing wrong?

Thanks

Regards


<html>
<head>

<script type="text/javascript">
// <![CDATA[
function validate()
{
// validation code here, which works fine
}

function valid1()
{
f=document.getElementById("Form1");
if(f.StaffCode.value<>"HS01")
{
alert("Invalied code. Please re-enter.");
f.StaffCode.focus();
return false;
}
}

// ]]>
</script>

</head>
<body>
<!--This form validates fine using function validate-->
<form id="theform" method="post" action="abc.asp" onsubmit="return
validate();">
<input type="hidden" name="mode" value="1">
<input type="text" name="muser" id="muser" value="" size="20">
<input type="password" name="mpass" id="mpass" value="" size="20">
<input name="bu_submit" type="image"
src="images/box/bu_login_sm.gif" border="0"
class="noborder" style="height: 31px;">
</form>

<!--This form does not validate using function valid1-->
<form id="Form1" method="post" action="xyz.asp" onsubmit="return
valid1();">
<input type="text" name="StaffCode" id="StaffCode" value=""
size="30">
<input name="bu_submit" type="image" src="images/box/bu_login.gif"
border="0" class="noborder"
style="height: 31px;">
</form>
</body>
</html>
 
C

Chagel

John said:
Hi

I have two forms on my page. Both use javascript to validate input before
submission. Problem is that first form does the validation fine but the
second form gets submitted without any validation taking place. Simplified
form of code is given below.

What am I doing wrong?

Thanks

Regards


<html>
<head>

<script type="text/javascript">
// <![CDATA[
function validate()
{
// validation code here, which works fine
}

function valid1()
{
f=document.getElementById("Form1");
if(f.StaffCode.value<>"HS01")
{
alert("Invalied code. Please re-enter.");
f.StaffCode.focus();
return false;
}
}

// ]]>
</script>

</head>
<body>
<!--This form validates fine using function validate-->
<form id="theform" method="post" action="abc.asp" onsubmit="return
validate();">
<input type="hidden" name="mode" value="1">
<input type="text" name="muser" id="muser" value="" size="20">
<input type="password" name="mpass" id="mpass" value="" size="20">
<input name="bu_submit" type="image"
src="images/box/bu_login_sm.gif" border="0"
class="noborder" style="height: 31px;">
</form>

<!--This form does not validate using function valid1-->
<form id="Form1" method="post" action="xyz.asp" onsubmit="return
valid1();">
<input type="text" name="StaffCode" id="StaffCode" value=""
size="30">
<input name="bu_submit" type="image" src="images/box/bu_login.gif"
border="0" class="noborder"
style="height: 31px;">
</form>
</body>
</html>


There is a grammar error of javascript£º

if(f.StaffCode.value<>"HS01")
=>
if(f.StaffCode.value != "HS01")





--

Begrds,

Mike Chen
http://chagel.com
 

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

Members online

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top