473,396 Members | 1,599 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Second form validation problem

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>
Jul 9 '06 #1
1 1453
"John" <Jo**@nospam.infovis.co.ukwrote in message
news:OG**************@TK2MSFTNGP03.phx.gbl...
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

Jul 9 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: TG | last post by:
Dear PHP Group, I have two forms that are used to collect user information. The first one takes user inputted values such as fullname, city, address etc. I want these values to display in the...
21
by: Stefan Richter | last post by:
Hi, after coding for days on stupid form validations - Like: strings (min / max length), numbers(min / max value), money(min / max value), postcodes(min / max value), telefon numbers, email...
4
by: bnp | last post by:
Hi All, I am quite new the JavaScript. Basically I am a C++ programmer, but now I am working on JavaScript since last 5 days. I have a problem regarding the form validation. I have created a...
9
by: julie.siebel | last post by:
Hello all! As embarrassing as it is to admit this, I've been designing db driven websites using javascript and vbscript for about 6-7 years now, and I am *horrible* at form validation. To be...
3
by: John | last post by:
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...
27
by: Chris | last post by:
Hi, I have a form for uploading documents and inserting the data into a mysql db. I would like to validate the form. I have tried a couple of Javascript form validation functions, but it...
11
by: Rik | last post by:
Hello guys, now that I'm that I'm working on my first major 'open' forms (with uncontrolled users I mean, not a secure backend-interface), I'd like to add a lot of possibilities to check wether...
4
by: Greg Scharlemann | last post by:
I'm trying to setup a dyamic dropdown list that displays a number of text fields based on the selected number in the dropdown. The problem I am running into is capturing the data already entered...
10
by: gweasel | last post by:
What is the best way to apply a Validation Rule - or rather, where is the best place to put it? Is there an advantage to putting it on the field in the table vs setting the validation rule on the...
5
by: lucyh3h | last post by:
Hi, I am trying to use XMLHttpRequest to do server side validation. I have several fields on a form and a submit button. The submit button has an event assocated with it when clicked. The...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.