如何验证多个下拉列表 [英] how to validate multiple drop down list

查看:64
本文介绍了如何验证多个下拉列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

喜!我已经尝试编写一个示例网站的代码我希望用户注册以便登录下面的代码将让你清楚地了解我正在做什么

我使用了5个不同的网页

他们是

home.html:



hi! guys i have been tryint to code a sample website i want users to register inorder to login the code below will give you a clear idea about what I'm doing
I have used 5 different web pages
they are
home.html:

<html>
<head>
<title>Home page</title>
<script type="text/javascript" language="javascript">
  function preventBack(){window.history.forward();}
  setTimeout("preventBack()", 0);
  window.onunload=function(){null};
</script>
</head>
<body bgcolor="black" text = "gold" oncontextmenu="return false" onselectstart="return false" ondragstart="return false">
<iframe src="header.html" frameborder="0" width=100% height=15%></iframe>
<iframe  src="center.html"frameborder="0" width=100% height=80%></iframe>
<iframe src="footer.html" frameborder="0" width=100% height=5% ></iframe>
</body>
</html>






你可以看到我将我的网页划分为3个部分

header.html:






as you can see I have divided my web page into 3 parts
header.html :

<html>
<head>
<script>
  function preventBack(){window.history.forward();}
  setTimeout("preventBack()", 0);
  window.onunload=function(){null};
</script>
</head>
<body bgcolor="black" text = "gold" oncontextmenu="return false" onselectstart="return false" ondragstart="return false">
<pre><img src="seal.jpg" width="50px" height="50px" align ="left"><h1 align ="right">My blog</h1> </pre>
</body>





center.html:



center.html:

<html>
<head>
<script type="text/javascript" language="javascript">
  function preventBack(){window.history.forward();}
  setTimeout("preventBack()", 0);
  window.onunload=function(){null};
</script>
</head>
<body bgcolor="black" text = "gold" oncontextmenu="return false" onselectstart="return false" ondragstart="return false" >
</body>
</html>





footer.html:



footer.html:

<html>
<head>
<script type="text/javascript" language="javascript">
  function preventBack(){window.history.forward();}
  setTimeout("preventBack()", 0);
  window.onunload=function(){null};
</script>
</head>
<body bgcolor="black" text = "gold" oncontextmenu="return false" onselectstart="return false" ondragstart="return false" >
</body>
</html>





next.html:



next.html:

<html>
<head>
<script language="JavaScript" type="text/javascript" src="info.js">
</script>
<body bgcolor="black" text = "gold" oncontextmenu="return false" onselectstart="return false" ondragstart="return false">
<pre>
<div align="left">
<form     action="finish.html" onsubmit="return checkForm(this)">
<h1>personal:</h1>
<table>
<tr>
<th><lable>Date Of Birth*:<lable></th><th><select name="month" id="month" onChange="changeDate(this.options[selectedIndex].value);">
<option value="0">Month</option>
<option value="1">January</option>
<option value="2">February</option>
<option value="3">March</option>
<option value="4">April</option>
<option value="5">May</option>
<option value="6">June</option>
<option value="7">July</option>
<option value="8">August</option>
<option value="9">September</option>
<option value="10">October</option>
<option value="11">November</option>
<option value="12">December</option>
</select></th><th><select name="day" id="day"><option value="0">Day</option></select></th><th><select name="year" id="year">
<option value="0">Year</option></select></th>
</tr>
<tr><th><lable> Age:*</lable></th><th><input type='text' name='age'  style='width:30px'/></th></tr>
<tr><th><lable> Gender:*</lable></th><th><input type='radio' name='gen'/>Male</th><th> <input type='radio' name='gen'/>Female</th></tr>
<tr><th><lable> Title:*</lable></th><th><select name="title" id="title">
<option value="0">Title</option>
<option value="1">Ms</option>
<option value="2">Mrs </option>
<option value="3">Mr</option>
</select></th><th></tr></table>
   <lable> Address:</lable>  <input type='text' name='addr' style='width:300px'/>
<hr>
<h1>Education:</h1>
<table>
<tr><th><lable> Qualification:*</lable></th><th><select name="qual" id="qual">
<option value="0"> </option>
<option value="1">Bs</option>
<option value="2">B.E/B.Tech </option>
</select></th><th></tr>
<tr>
<th><lable> Stream:*</lable></th><th><select name="strm" id="strm">
<option value="0"> </option>
<option value="1">CS</option>
<option value="2">EC</option>
<option value="3">EE</option>
<option value="4">Mech</option>
<option value="5">Civil</option>
<tr><th><lable> SkillSet:*</lable></th></tr>
</table>

        <input type='Checkbox' name='ss1'/>C      <input type='Checkbox' name='ss2'/>C++
        <input type='Checkbox' name='ss3'/>JAVA   <input type='Checkbox' name='ss4'/>HTML5
        <input type='Checkbox' name='ss5'/>C#     <input type='Checkbox' name='ss6'/>PHP



                  <input type='submit'value="Finish"/>      <input type='reset'value="reset"/>
</form>
</div>
</pre>
</body>
<html>







finish.html:




finish.html:

<html>
<head>
<script type="text/javascript" language="javascript">
  function preventBack(){window.history.forward();}
  setTimeout("preventBack()", 0);
  window.onunload=function(){null};
</script>
</head>
<body bgcolor="black" text = "gold" oncontextmenu="return false" onselectstart="return false" ondragstart="return false">
<font size="10" color="cryn">
<p align="center">Thank you!</br>
your Registration is successful!!</p></br>
</font>
<font size="5" color="white">
<p> your Id and other  details about your account will be communicated to you through  your registered mail id</p>
</font>
</body>





the jave scripts that i’m using are....

info.js:



the jave scripts that i'm using are....
info.js:

function changeDate(i)
{
var e = document.getElementById('day');
while(e.length>0)
e.remove(e.length-1);
var j=-1;
if(i=="0")
k=0;
else if(i==2)
k=29;
else if(i==4||i==6||i==9||i==11)
k=30;
else
k=31;
while(j++<k)
{
var s=document.createElement('option');
var e=document.getElementById('day');
if(j==0)
{
s.text="Day";
s.value="na";
try
{
e.add(s,null);
}
catch(ex){
e.add(s);}
}
else
{
s.text=j;
s.value=j;
try
{
e.add(s,null);
}
catch(ex)
{
e.add(s);
}
}
}
var y = 2010;
while (y-->1909)
{
var s = document.createElement('option');
var e = document.getElementById('year');
s.text=y;
s.value=y;
try
{
e.add(s,null);
}
catch(ex)
{
e.add(s);
}
}
}

//form validation


function checkForm(form)
  {
//check dob
  if(document.getElementById("month").value == 0)
    {
      alert("Error: please enter the birth month!");
      form.month.focus();
      return false;
    }

  if(document.getElementById("day").value == 0)
    {
      alert("Error: please enter the birth day!");
      form.day.focus();
      return false;
    }
  if(document.getElementById("year").value == 0)
    {
      alert("Error: please enter the birth year!");
      form.year.focus();
      return false;
    }

//check age
   else if(form.age.value == "")
    {
      alert("Error: age cannot be blank!");
      form.age.focus();
      return false;
    }
    re = /^[0-9]*$/;
    if(!re.test(form.fname.value))
     {
      alert("Error:  ae must contain numbers only");
      form.age.focus();
      return false;
     }



 else if(document.getElementById("title").value == 0)
    {
      alert("Error: please enter the title!");
      form.title.focus();
      return false;
    }
else if(document.getElementById("qual").value == 0)
    {
      alert("Error: please enter the qualification!");
      form.qual.focus();
      return false;
    }
else if(document.getElementById("strm").value == 0)
    {
      alert("Error: please enter the stream!");
      form.strm.focus();
      return false;
    }
}
function preventBack(){window.history.forward();}
  setTimeout("preventBack()", 0);
  window.onunload=function(){null};



reg1.js:


reg1.js:

function checkForm(form)
  {
//check first name
    if(form.fname.value == "")
    {
      alert("Error: First name cannot be blank!");
      form.fname.focus();
      return false;
    }
    re = /^[a-zA-Z]*$/;
    if(!re.test(form.fname.value))
     {
      alert("Error: First name must contain only letters, numbers and underscores!");
      form.fname.focus();
      return false;
     }
//check last name
 if(form.lname.value == "")
    {
      alert("Error: Last name cannot be blank!");
      form.lname.focus();
      return false;
    }
    re = /^[a-zA-Z]*$/;
    if(!re.test(form.lname.value)) {
      alert("Error: Last name must contain only letters, numbers and underscores!");
      form.lname.focus();
      return false;
    }
//check userid

 if(form.uid.value != "" && form.uid.value == form.cuid.value) {
    re = /^[a-zA-Z][a-zA-Z0-9]*$/;
    if(!re.test(form.uid.value)) {
      alert("Error: user id  must contain only letters and numbers !");
      form.uid.focus();
      return false;
}
}
else
{
      alert("Error: check your uid....uid invalid!!");
      form.uid.focus();
      return false;
    }

//check password
    if(form.passwd.value != "" && form.passwd.value == form.cpasswd.value) {
      if(form.passwd.value.length < 6) {
        alert("Error: Password must contain at least six characters!");

        form.password.focus();
        return false;
      }
      if(form.passwd.value == form.uid.value) {
        alert("Error: Password must be different from Username!");
        form.password.focus();
        return false;
      }
      re = /[0-9]/;
      if(!re.test(form.passwd.value)) {
        alert("Error: password must contain at least one number (0-9)!");
        form.password.focus();
        return false;
      }
      re = /[a-z]/;
      if(!re.test(form.passwd.value)) {
        alert("Error: password must contain at least one lowercase letter (a-z)!");
        form.password.focus();
        return false;
      }
      re = /[A-Z]/;
      if(!re.test(form.passwd.value)) {
        alert("Error: password must contain at least one uppercase letter (A-Z)!");
        form.password.focus();
        return false;
      }
    } else {
      alert("Error: Please check that you've entered and confirmed your password!");
      form.passwd.focus();
      return false;
    }

    alert("You entered a valid password: " + form.password.value);
    return true;
  }

function preventBack(){window.history.forward();}
  setTimeout("preventBack()", 0);
  window.onunload=function(){null};





I know the code is not optimized and also it is not not fit to be converted to a website and many of you might feel it is outdated also .but this is the requirements I was given to work with.the problem here is i am unable to validate all the drop down lists that I have. could someone help me with this so that I can finish my sample website.

Thanks in advance



I know the code is not optimized and also it is not not fit to be converted to a website and many of you might feel it is outdated also .but this is the requirements I was given to work with.the problem here is i am unable to validate all the drop down lists that I have. could someone help me with this so that I can finish my sample website.
Thanks in advance

推荐答案

/;
if(!re.test(form.fname.value))
{
alert(\"Error: ae must contain numbers only\");
form.age.focus();
return false;
}



else if(document.getElementById(\"title\").value == 0)
{
alert(\"Error: please enter the title!\");
form.title.focus();
return false;
}
else if(document.getElementById(\"qual\").value == 0)
{
alert(\"Error: please enter the qualification!\");
form.qual.focus();
return false;
}
else if(document.getElementById(\"strm\").value == 0)
{
alert(\"Error: please enter the stream!\");
form.strm.focus();
return false;
}
}
function preventBack(){window.history.forward();}
setTimeout(\"preventBack()\", 0);
window.onunload=function(){null};
/; if(!re.test(form.fname.value)) { alert("Error: ae must contain numbers only"); form.age.focus(); return false; } else if(document.getElementById("title").value == 0) { alert("Error: please enter the title!"); form.title.focus(); return false; } else if(document.getElementById("qual").value == 0) { alert("Error: please enter the qualification!"); form.qual.focus(); return false; } else if(document.getElementById("strm").value == 0) { alert("Error: please enter the stream!"); form.strm.focus(); return false; } } function preventBack(){window.history.forward();} setTimeout("preventBack()", 0); window.onunload=function(){null};



reg1.js:


reg1.js:

function checkForm(form)
  {
//check first name
    if(form.fname.value == "")
    {
      alert("Error: First name cannot be blank!");
      form.fname.focus();
      return false;
    }
    re = /^[a-zA-Z]*


/;
if(!re.test(form.fname.value))
{
alert(\"Error: First name must contain only letters, numbers and underscores!\");
form.fname.focus();
return false;
}
//check last name
if(form.lname.value == \"\")
{
alert(\"Error: Last name cannot be blank!\");
form.lname.focus();
return false;
}
re = /^[a-zA-Z]*
/; if(!re.test(form.fname.value)) { alert("Error: First name must contain only letters, numbers and underscores!"); form.fname.focus(); return false; } //check last name if(form.lname.value == "") { alert("Error: Last name cannot be blank!"); form.lname.focus(); return false; } re = /^[a-zA-Z]*


/;
if(!re.test(form.lname.value)) {
alert(\"Error: Last name must contain only letters, numbers and underscores!\");
form.lname.focus();
return false;
}
//check userid

if(form.uid.value != \"\" && form.uid.value == form.cuid.value) {
re = /^[a-zA-Z][a-zA-Z0-9]*
/; if(!re.test(form.lname.value)) { alert("Error: Last name must contain only letters, numbers and underscores!"); form.lname.focus(); return false; } //check userid if(form.uid.value != "" && form.uid.value == form.cuid.value) { re = /^[a-zA-Z][a-zA-Z0-9]*


这篇关于如何验证多个下拉列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆