学习java web技术ing

js表单验证

用js验证表单提交时不能为空的代码:

 
<script type="text/javascript">
 function check(form){
  with(create_apply_form){
   if(profession.value == ""){
    alert("专业名称不能为空");
    return false;
   }
   if(classes.value == ""){
    alert("班级不能为空");
    return false;
   }
   if(name.value == ""){
    alert("姓名不能为空");
    return false;
   }
   if(student_number.value == ""){
    alter("学号不能为空");
    return false;
   }
   if(contact_way.value == ""){
    alter("联系方式不能为空");
    return false;
   }
   if(apply_item_id.value == ""){
    alter("已报名的项目id不能为空");
    return false;
   }
   return true;
  }
 }
</script>
 
 
在表单中input框submit中要写多一句:onclick="return check(form);":即
<input type="submit" value="新增" onclick="return check(form);">

posted on 2014-02-24 22:09  学技术中的小明  阅读(166)  评论(0编辑  收藏  举报

导航