您的位置:首页 > Web前端 > JavaScript

表单提交验证的javascript

2008-07-29 13:49 435 查看
//单一form时

var Choice3=document.getElementsByName('Choice3')[0]; //getElementsByName得到的是同名element数组,要用下标

不是documen.Form.getElementsByName,费了好几个小时就因为多写了个form
var Choice4=document.getElementsByName('Choice4')[0];
if(Choice3.value==""){
alert("Choice3");
return false;
}
if(Choice4.value==""){
alert("Choice4");
return false;
}
return true;

//多form时

if(form.name=="Form"){
var DateCombo1=document.Form.elements['DateCombo1'];
var DateCombo2=document.Form.elements['DateCombo2'];
var Choice1=document.Form.elements['Choice1'];
var Choice2=document.Form.elements['Choice2'];
var Choice3=document.Form.elements['Choice3'];
var Choice4=document.Form.elements['Choice4'];
var TextArea1=document.Form.elements['TextArea1'];
if(DateCombo1.value=='^DATE^'){
alert("DateCombo1");
return false;
}
if(DateCombo2.value=='^DATE^'){
alert("DateCombo2");
return false;
}
if(Choice1.value.length==0){
alert("Choice1");
return false;
}
if(Choice2.value.length==0){
alert("Choice2");
return false;
}
if(Choice3.value.length==0){
alert("Choice3");
return false;
}
if(Choice4.value.length==0){
alert("Choice4");
return false;
}
if(TextArea1.value.length==0){
alert("TextArea1");
return false;
}
return true;
}

else{
return true;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: