473,396 Members | 1,834 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
3 1245

John wrote:
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?
If you want to know what's wrong with your javascript, you should post
to a javascript group - microsoft.public.scripting.jscript, for
example.

But client side validation is not recommended. It does not work for
those with javascript disabled, or those that want to get round it.
And having acceptable log in values accessible to all through View
Source rather defeats the whole point. You should move to server-side
validation.

--
Mike Brind

Jul 9 '06 #2
Thanks. I just want a way to validate the second form and not necessarily
via javascript. Any help would be appreciated. The validation required is
not fort Knox standard though, just to deter a casual user.

Thanks

Regards

"Mike Brind" <pa*******@hotmail.comwrote in message
news:11**********************@75g2000cwc.googlegro ups.com...
>
John wrote:
>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?

If you want to know what's wrong with your javascript, you should post
to a javascript group - microsoft.public.scripting.jscript, for
example.

But client side validation is not recommended. It does not work for
those with javascript disabled, or those that want to get round it.
And having acceptable log in values accessible to all through View
Source rather defeats the whole point. You should move to server-side
validation.

--
Mike Brind

Jul 9 '06 #3
On Sun, 09 Jul 2006 00:28:53 -0500, John <Jo**@nospam.infovis.co.ukwrote:
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?
Not tested, but this is most likely the problem.
if(f.StaffCode.value<>"HS01")
The inequality operator is != in Javascript. Also, your script will work
more reliably if you use the DOM methods to access StaffCode directly
rather than via its parent form.

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

--
Justin Piper
Bizco Technologies
http://www.bizco.com/
Jul 10 '06 #4

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...
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...
1
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: 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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
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...
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.