473,394 Members | 1,765 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,394 software developers and data experts.

Need help with JavaScript validation for multiple forms

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.indexOf("@")!= "-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.length !=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.charAt(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.focus();
return false;
}
if (do_checkEmpty(form.lastname) == false){
alert("Please Enter Last Name.");
form.lastname.focus();
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 1426
dmjpro
2,476 2GB
plz send ur html code ....

i am online ...
Feb 24 '07 #2
plz send ur html code ....

i am online ...
Thank for your help
here are the UR for two form
http://cs.metrostate.edu/~ics499sp0702/Khuong/Info.html
http://cs.metrostate.edu/~ics499sp0702/Khuong/Customer.html
Feb 24 '07 #3
dmjpro
2,476 2GB
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_obj)
{
if(checkForm(form_obj)) document.forms[0].submit();
}

and edit ...

checkForm(form){

if (do_checkEmail(form.emailAdd) == false){
alert("Please enter a valid email.");
form.emailAdd.focus();
return false;
}
if (do_checkEmpty(form.lastname) == false){
alert("Please Enter Last Name.");
form.lastname.focus();
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_checkEmail(form.emailAdd) == false){
alert("Please enter a valid email.");
form.emailAdd.focus();
return false;
}

now try urself ... best of luck
Feb 25 '07 #4
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
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...
1
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,...
7
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...
2
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. ...
2
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...
2
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"...
5
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...
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...
2
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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
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,...
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
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...

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.