473,756 Members | 2,061 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Simple Form Validation

I've been playing with this form validation method for a while and have
tried an array of things but haven't had any luck with a couple items.

1. The validateForm() function doesn't detect when the Min price is
greater than the maximum price.
2. The validateForm() function doesn't call isNumber() on the minBaths,
maxBaths, minBeds, or maxBeds.
3. Despite errors in input and the validateForm() function returning
false, the form is still submitted.

These are probably obvious fixes...I'm just not seeing them. thanks for
any help.

Here's the code:
<html>
<head>
<title></title>
<link rel="stylesheet " href="css/main.css">
<script language="JavaS cript">
<!--
function validateForm(th isForm){
alert("validate Form() called");
//alert("'" + thisForm.minBat hs.value + "'");
//alert(isNumber( thisForm.minBat hs.value));
if (thisForm.minPr ice.value == "") {
alert("You must enter a starting price.");
thisForm.minPri ce.focus();
return false;
} else if(!isNumber(th isForm.minPrice .value)) {
alert("Please enter a number for the starting price.");
thisForm.minPri ce.focus();
return false;
} else if (thisForm.maxPr ice.value == "") {
alert("You must enter a maximum price.");
thisForm.maxPri ce.focus();
return false;
} else if(!isNumber(th isForm.maxPrice .value)) {
alert("Please enter a number for the maximum price.");
thisFormForm.ma xPrice.focus();
return false;
} else if(thisForm.min Price.valueOf() >
thisForm.maxPri ce.valueOf()) {
alert("The starting value is greater than the maximum price.");
thisForm.minPri ce.focus();
return false;
} else if(!isNumber(th isForm.minBaths .value)) {
alert("Please enter a number for the minimum bathrooms.");
thisForm.minBat hs.focus();
return false;
} else if(!isNumber(th isForm.maxBaths .value)) {
alert("Please enter a number of the maximum bathrooms.");
thisForm.maxBat hs.focus();
} else if(!isNumber(th isForm.minBeds. value)) {
alert("Please enter a number for the minimum bedrooms.");
thisForm.minBed s.focus();
return false;
} else if(!isNumber(th isForm.maxBeds. value)) {
alert("Please enter a number for the maximum bedrooms.");
thisForm.maxBed s.focus();
return false;
} else {
return false;
}
}

function isNumber(entry) {
//alert("isNumber () Called");
validChar='0123 456789'; // characters allowed
strlen=entry.le ngth; // how long is test string
if (strlen < 1) {return false;} // no check!
// Now scan string for illegal characters
for (i=0; i < strlen; i++ ) {
if (validChar.inde xOf(entry.charA t(i)) < 0) {
return false;
}
}
//alert("returnin g true");
return true;
}

//-->
</script>
</head>
<body>
<!-- HEADER START -->
<table border="0" width="100%" cellpadding="0" cellspacing="0" >
<tr>
<td class="bottombo rder" colspan="3">
<div align="right" style="font-size:12px;">| <a
href="/">Home</a> |
<a href="/about.php">Abou t</a> |
<a href="/contact.php">Co ntact</a> |&nbsp;</div>
</td>
</tr>
<!-- HEADER END -->
<tr>
<td valign="top" width="550">
<form name="searchFor m" onSubmit="retur n validateForm(th is)"
method="post">
<input type="hidden" name="advanced" value="true" />
<input type="hidden" name="valid" value="true" />
<table width="600" cellspacing="1" cellpadding="1" border="0"
class="padLeft" >
<tr>
<td nowrap align="right">S treet:</td>
<td colspan="7" nowrap>&nbsp;&n bsp;&nbsp;<inpu t
type="text" name="StreetNam e" size="30" value=""/></td>
</tr>
<tr>
<td nowrap align="right">C ity:</td>
<td nowrap colspan="4">&nb sp;&nbsp;&nbsp; <input
type="text" name="City" size="20"
value=""/>&nbsp;&nbsp;&n bsp;&nbsp;&nbsp ;&nbsp;State:
&nbsp;&nbsp;&nb sp;
<select name="State">
<option value="NC">NC</option>
<option value="SC">SC</option>
</select>
<span
style="padding-left:6px;paddin g-right:6px;font-size:12px;font-weight:bold;col or:$999";>-OR-</span>
Zip Code:&nbsp;&nbs p;&nbsp;<input type="text" name="ZipCode" size="6"
maxlength="5" value=""/></td>
</tr>
<tr>
<td colspan="5">&nb sp;</td>
</tr>
<td colspan="5" style="padding-left:10px">
<table border="0" cellpadding="1" cellspacing="1" >
<tr>
<td nowrap align="right">M in Price:</td>
<td nowrap>&nbsp;&n bsp;&nbsp;<inpu t type="text"
name="minPrice" size="4" value="120000"/></td>
<td nowrap align="right">M ax Price:</td>
<td nowrap>&nbsp;&n bsp;&nbsp;<inpu t type="text"
name="maxPrice" size="4" value="125000"/></td>
</tr>
<tr>
<td nowrap align="right">M in Beds:</td>
<td nowrap>&nbsp;&n bsp;&nbsp;<inpu t type="text"
name="minBeds" size="4" maxlength="2" /></td>
<td nowrap align="right">M ax Beds:</td>
<td nowrap>&nbsp;&n bsp;&nbsp;<inpu t type="text"
name="maxBeds" size="4" maxlength="2" /></td>
</tr>
<tr>
<td nowrap align="right">M in Baths:</td>
<td nowrap>&nbsp;&n bsp;&nbsp;<inpu t type="text"
name="minBaths" size="4" maxlength="2" value="ax" /></td>
<td nowrap width="75" align="right">M ax Baths:</td>
<td nowrap>&nbsp;&n bsp;&nbsp;<inpu t type="text"
name="maxBaths" size="4" maxlength="2" /></td>
</tr>
</table>
</td>
</tr>
<tr>
<td>&nbsp;</td>
<td colspan="3"><in put type="submit" value="Submit"
name="submit" /></td>
</tr>
</table>
</form>
</td>
</tr>
</table>
</body>
</html>

Oct 15 '05
11 2532
Michael Winter wrote:
On 15/10/2005 21:28, gr************* *@gmail.com wrote:
<!--


Don't use SGML comment delimiters in SCRIPT elements.


That would still allow for "<!" and ">" :)

Better to say not to use SGML CDO (Comment Declaration Open[1]) and
CDC (Comment Declaration Close[2]) delimiters in `script' elements.
SCNR

PointedEars
___________
[1] Informal abbreviation to be found in W3C WG's docs for "SGML
Declaration Open delimiter followed by SGML Comment Open delimiter"
[2] Informal abbreviation to be found in W3C WG's docs for "SGML
Comment Close delimiter followed by SGML Declaration Close delimiter"
--
The English government is much of a German poodle as
other governments. The Germans infiltrated them all.
-- "The only real Barbara Schwarz", dsw.scientology ,
<16************ **************@ posting.google. com>)
Oct 18 '05 #11
Nag

if(okay)
return true;
else
return false;

You mean
return okay

yeah..thats correct. I should have mentioned single line
statement..than ks.

Nag.

Oct 18 '05 #12

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

Similar topics

17
8294
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 with form elements that turn out to be arrays that have to be compared with one another! I have one form element, languages, a checkbox group. Beside each checkbox is a dropdown, proficiency (which will become proficiency alongside languages)....
4
9983
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 performing the validation check on the values that were entered into the form, I simply repost the form to perform the PHP validation. If any of the values that have been entered into the form are incorrect, I display a warning message on the screen...
7
2976
by: r0adhog | last post by:
I have a very simple form: <html> <head> </head> <body> <% function ValForm() if len(document.form.newapp.all("AccessCode").Value) = 4 then document.form.newapp.submit()
3
1649
by: Marc Llenas | last post by:
Hi there, I'm stuck on a validation function for a form and I cannot figure out what the problem is. The page is in ASP. Any ideas? The function being called is: <script language="JavaScript" type="text/javascript"> function checkform ( form ) {
16
2250
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 individual fields, such as an "Email Validation Script" or a "Phone Validation Script". Is it ok to put all these scripts on page as they are or should they be joined in some way together to be one script? I'm a total JavaScript newbie and am completely...
2
8403
by: Hazzard | last post by:
I just realized that the code I inherited is using all asp.net server controls (ie. webform controls) and when I try to update textboxes on the client side, I lose the new value of the textbox when submitting the form to update the database. The server doesn't have the client side value any more. It seems to me that as I begin to write the client side javacript code for form validation and client side editing capabilities in order to save...
18
3041
by: Q. John Chen | last post by:
I have Vidation Controls First One: Simple exluce certain special characters: say no a or b or c in the string: * Second One: I required date be entered in "MM/DD/YYYY" format: //+4 How ??
9
4179
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.)
27
4753
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
3000
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...
0
9325
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9152
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9930
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
9716
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...
1
9716
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8569
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...
0
6410
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
4996
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...
0
5180
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.