473,474 Members | 1,673 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Form Validation

The script I have written below works perfect to make sure that each
text field in a form is not left with the default value of "0". The
problem is that I need it to only produce the alert if all fields are
left with the value or "0". In other words if one of the fields has
been changed to a "1" but the other are still all "0" then it should
not produce an alert. I am new at javascript and it took me over an 1
1/2 to get this far and I am stuck. Any help would be greatly
appreciated.
<SCRIPT LANGUAGE="Javascript">
function checkForm(form) {
for (var i = 0; 1 < form.elements.length; i++) {
if (form.elements[i].value == 0) {
alert("Fill out All fields.")
return false
}
}
return true
}
</script>

<form method="post" action="http://www.balls.com" onSubmit='return
checkForm(this);'>
Item 1 : <input type="text" name="quantity1" value="0"><br>
Item 2 : <input type="text" name="quantity2" value="0"><br>
Item 3 : <input type="text" name="quantity3" value="0"><br>
<input type="submit" value="send">
</form>
Jul 20 '05 #1
1 3267
VK
var OK = false;
for (var i = 0; 1 < form.elements.length; i++) {
if (form.elements[i].value) {
OK = true; break; // at least one field is not equal 0 - break the loop
}
}
if (OK) {...}
else {alert(...)}

Wayne <wa***@lysoft.com> wrote in message
news:d9**************************@posting.google.c om...
The script I have written below works perfect to make sure that each
text field in a form is not left with the default value of "0". The
problem is that I need it to only produce the alert if all fields are
left with the value or "0". In other words if one of the fields has
been changed to a "1" but the other are still all "0" then it should
not produce an alert. I am new at javascript and it took me over an 1
1/2 to get this far and I am stuck. Any help would be greatly
appreciated.
<SCRIPT LANGUAGE="Javascript">
function checkForm(form) {
for (var i = 0; 1 < form.elements.length; i++) {
if (form.elements[i].value == 0) {
alert("Fill out All fields.")
return false
}
}
return true
}
</script>

<form method="post" action="http://www.balls.com" onSubmit='return
checkForm(this);'>
Item 1 : <input type="text" name="quantity1" value="0"><br>
Item 2 : <input type="text" name="quantity2" value="0"><br>
Item 3 : <input type="text" name="quantity3" value="0"><br>
<input type="submit" value="send">
</form>

Jul 20 '05 #2

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

Similar topics

17
by: Phil Powell | last post by:
Where can I find an online PHP form validator script library to use? I have tried hacking the one here at work for weeks now and it's getting more and more impossible to customize, especially now...
4
by: TG | last post by:
I have a validation form that must behave differently based on the results of a PHP validation check. I have a post command at the top of my form that calls itself. I don't leave the form when...
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...
16
by: Hosh | last post by:
I have a form on a webpage and want to use JavaScript validation for the form fields. I have searched the web for form validation scripts and have come up with scripts that only validate...
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...
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...
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...
7
ak1dnar
by: ak1dnar | last post by:
Hi, I got this scripts from this URL There is Error when i submit the form. Line: 54 Error: 'document.getElementbyID(....)' is null or not an object What is this error. Complete Files
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
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...
1
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...
1
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...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
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 ...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
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...

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.