473,791 Members | 3,111 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Need help with JavaScript validation for multiple forms

4 New Member
Hello, Please help me with this code..I have 4 forms which link to different htmll page. I try to write one validation file that can validate for the form whenever user click on that form.How do I call Validate.js for each form? Please give me some hints.
Thanks

Validate.js
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
//test version
//read the comment i put
///////////////////////////////////////////////////////////////////////////////////////////////////////////
function do_checkEmail(x ){
//do all email checking
if(x.value.inde xOf("@")!= "-1" && x.value.indexOf (".") != "-1"){
return false;
}
else
{
return true;

}
}
function do_checkPhone(x ){
//do all phone checking phone format 999-999-9999
if(x.value.leng th !=12){
return false;
}

for(var i = 0; i < x.value.length; i++){
if ((i>-1&&i<3)||(i>3 && i<7)||(i>7&& i>12)){
if(x.value.char At(i) < "0" || x.value.charAt( i) > "9"){
return false;
}
}
//check for hyphen '-'
else if (x.value.charAt (i) != "-"){
return false;
}
}
return true;
}
//Check for empty field, last name and first name
function do_checkEmpty(x ){
if (x.value == "" || x.value == "null"){
return false;
}
else{
return true;
}

}

function checkForm(form) {

if (do_checkEmail( form.emailAdd) == false){
alert("Please enter a valid email.");
form.emailAdd.f ocus();
return false;
}
if (do_checkEmpty( form.lastname) == false){
alert("Please Enter Last Name.");
form.lastname.f ocus();
return false;
}
if (do_checkEmpty( form.firstname) == false){
alert("Please Enter First Name.");
form.firstname. focus();
return false;
}
return true;

}
//////////////////////////////////////////////////////////////////////
Feb 24 '07 #1
4 1436
dmjpro
2,476 Top Contributor
plz send ur html code ....

i am online ...
Feb 24 '07 #2
kktnguyen
4 New Member
plz send ur html code ....

i am online ...
Thank for your help
here are the UR for two form
http://cs.metrostate.e du/~ics499sp0702/Khuong/Info.html
http://cs.metrostate.e du/~ics499sp0702/Khuong/Customer.html
Feb 24 '07 #3
dmjpro
2,476 Top Contributor
i don't understand how u link two html pages..
i think u are showing the pages in seperate windows

add a function in js ...

function myCheck(form_ob j)
{
if(checkForm(fo rm_obj)) document.forms[0].submit();
}

and edit ...

checkForm(form) {

if (do_checkEmail( form.emailAdd) == false){
alert("Please enter a valid email.");
form.emailAdd.f ocus();
return false;
}
if (do_checkEmpty( form.lastname) == false){
alert("Please Enter Last Name.");
form.lastname.f ocus();
return false;
}
if (do_checkEmpty( form.firstname) == false){
alert("Please Enter First Name.");
form.firstname. focus();
return false;
}
return true;

}

before validate ...
check the existence of that object ..

if (typeof form.email != 'undefined' && Adddo_checkEmai l(form.emailAdd ) == false){
alert("Please enter a valid email.");
form.emailAdd.f ocus();
return false;
}

now try urself ... best of luck
Feb 25 '07 #4
kktnguyen
4 New Member
Thank you much I will give it a try.

k
Feb 26 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

4
4978
by: Phil Powell | last post by:
Has anyone here ever done a case where you have a select multiple form element and you have to do both server-side and client-side validation? I am honestly not sure how to do it in Javascript (I keep getting errors thrown that I can't verify because the form processes onto itself too quickly for me to check the Javascript errors) because the select multiple form element name has to be in the form of "var" because PHP will then recognize...
1
2638
by: Griff | last post by:
Hi! I'm using JavaScript on an HTML page for form validation. I have a form value (theForm.ProdType1) which represents a picklist from which users may make multiple selections; essentially, this is a Select object with the "multiple" attribute. There are 20 options to choose from in this object; one of the options (we'll call it option X) should NEVER be selected with any other option in the object. Let's say that the user has...
7
2360
by: Jack Addington | last post by:
I've got a fairly simple application implementation that over time is going to get a lot bigger. I'm really trying to implement it in a way that will facilitate the growth. I am first writing a WinForms interface and then need to port that to a web app. I am kinda stuck on a design issue and need some suggestions / direction. Basically I have a business layer that I want to use to process any dataentry logic (row focus changes, data...
2
13274
by: techfuzz | last post by:
I scoured this group and others looking for the best way to disable a button after the first click to prevent multiple submissions, but never did find anything that worked like they said it would. I went ahead and wrote my own bit of code so I'm sharing it here for everyone. Even though it doesn't really disable the button by greying it out, it prevents the multiple submissions which it what I was attempting to prevent all along. ...
2
1187
by: Bobby | last post by:
Hi all, I want to validate my page with ASP.NET Validator controls. It works well, but I have 2 form in one page. My problem is that, If I input form1, and I click submit, It will also validate the form2 (that I don't input), so I can't submit the form1. Actually this can be solve if I write javascript, but If I want to use Server Validator,is there a way to do this? Please help...
2
4895
by: this one | last post by:
I have the following code <html> <head> <title>Untitled Document</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <script language="JavaScript" src="..\include\gen_validatorv2.js" type="text/javascript"></script> </head>
5
2474
by: Phil Powell | last post by:
Requirement is to refresh a page in the form of a continual form submittal (for server-side validation and action) Here is the Javascript I came up with that I thought would do that: <script type="text/javascript"> function generateForm() { document.forms.elements.name = 'username'; document.forms.elements.type = 'hidden'; document.forms.elements.value = 'ppowell'
27
4759
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...
2
3017
by: swethak | last post by:
hi , i write the code in .htm file. It is in cgi-bin/searches/one.htm.In that i write a form submitting and validations.But validations are not worked in that .htm file. I used the same code in my local system that validations work.plz tell that whats the problem in that. Here is my code <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html...
0
9669
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
10428
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
10207
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
10156
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
9997
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9030
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
5559
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4110
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
3718
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.