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;
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
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;
}