473,698 Members | 2,186 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.getE lementById("For m1");
if(f.StaffCode. value<>"HS01")
{
alert("Invalied code. Please re-enter.");
f.StaffCode.foc us();
return false;
}
}

// ]]>
</script>

</head>
<body>
<!--This form validates fine using function validate-->
<form id="theform" method="post" action="abc.asp " onsubmit="retur n
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="retur n
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 1470
"John" <Jo**@nospam.in fovis.co.ukwrot e in message
news:OG******** ******@TK2MSFTN GP03.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.getE lementById("For m1");
if(f.StaffCode. value<>"HS01")
{
alert("Invalied code. Please re-enter.");
f.StaffCode.foc us();
return false;
}
}

// ]]>
</script>

</head>
<body>
<!--This form validates fine using function validate-->
<form id="theform" method="post" action="abc.asp " onsubmit="retur n
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="retur n
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
4257
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 second form when it is called. Both forms are .htm files that call themselves when the submit button is press via the following command in each form: <form method="post" action="<?php $server?>">
21
3910
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 adresses and so on. I thought it might be a better way to programm an automated, dynamic form validation that works for all kinds of fields, shows the necessary error messages and highlights the coresponding form fields.
4
2643
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 script that validates the form fields. the validation procedure is called ONCLICK event of the submit button. Follwowing is the structure of the validation procedure.
9
4173
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 honest I usually hire someone to do it for me, grab predone scripts and kind of hack out the parts that I need, or just do very minimal validation (e.g. this is numeric, this is alpha-numeric, etc.)
3
1259
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 validation taking place. Simplified form of code is given below. What am I doing wrong? Thanks
27
4745
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 appears that the data goes straight to the processing page, rather than the javascript seeing if data is missing and popping up an alert. I thought it may be because much of the form is populated with data from the db (lists, etc.), but when I leave...
11
2994
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 certain fields match certain criteria, and inform the user in different ways when the data is wrong (offcourse, this will be checked on posting the data again, but that's something I've got a lot of experience with). Now, offcourse it's...
4
2630
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 before the list is repopulated. For example, suppose the user selects 3 in the drop down list and 3 text fields are shown. If the user populates the 3 text fields with data and decides to change the drop down to a list of 4 or 5, how do I capture...
10
5719
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 form the control is on? Basically I have a number of controls in a form that are required, and to check it I am setting the Validation Rule to "<>"IsNull" so that when the user tries to tab through/click out of a required area without entering...
5
3219
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 javascript method will do the form validation for each field one by one. For each field, an XMLHttpRequst will be made to a PHP file and get the return, either set an error field (<span>'s innerHTML) or leave it empty. Then I'll check the error field...
0
9157
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9028
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7728
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6518
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5860
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4369
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3046
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2330
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2001
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.