heidari68
شنبه 21 تیر 1393, 09:10 صبح
سلام دوستان
من کد زیر رو برای اعتبار سنجی فرم نوشتم که خالی رد نشه.
ولی چک باکس و دکمه های رادیویی و لیست کشویی را نمی دونم باید چه طور چک کنم که خالی رد نشه
ممنونم
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script language="javascript">
function check_form(){
if(document.getElementById('name').value==""){
alert("fill the name") ;
document.getElementById('name').focus();
return false;
}
if(document.getElementById('family').value==""){
alert("fill the family") ;
document.getElementById('family').focus();
return false;
}
if(document.getElementById('username').value==""){
alert("fill the username") ;
document.getElementById('username').focus();
return false;
}
if(document.getElementById('pass').value==""){
alert("fill the pass") ;
document.getElementById('pass').focus();
return false;
}
if(document.getElementById('repass').value==""){
alert("fill the repass") ;
document.getElementById('repass').focus();
return false;
}
if(document.getElementById('q').value==""){
alert("fill the q") ;
document.getElementById('q').focus();
return false;
}
if (document.getElementById('pass').value!=document.g etElementById('repass').value){
alert("not same") ;
document.getElementById('repass').select();
return false;
}
return true;
}
</script>
</head>
<body>
<form action="a.html" method="post" onsubmit="return check_form()">
<table border="1" align="center">
<tr>
<td><input type="text" name="name" id="name" /></td>
<td>نام</td>
<td>*</td>
</tr>
<tr>
<td><input type="text" name="family" id="family"/></td>
<td>فامیلی</td>
<td>*</td>
</tr>
<tr>
<td><input type="text" name="username" id="username"/></td>
<td>نام کاربری</td>
<td>*</td>
</tr>
<tr>
<td><input type="password" name="pass" id="pass" /></td>
<td>رمز</td>
<td>*</td>
</tr>
<tr>
<td><input type="password" name="repass" id="repass" /></td>
<td>تکرار رمز</td>
<td>*</td>
</tr>
<input type="checkbox" id="q" />
<input type="radio" id="e" />
<select>
<option>a</option>
<option>b</option>
</select>
<tr align="center">
<td colspan="3"><input type="reset" value="نوسازی" /><input type="submit" value="ارسال" /></td>
</tr>
</table>
</form>
</body>
</html>
من کد زیر رو برای اعتبار سنجی فرم نوشتم که خالی رد نشه.
ولی چک باکس و دکمه های رادیویی و لیست کشویی را نمی دونم باید چه طور چک کنم که خالی رد نشه
ممنونم
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script language="javascript">
function check_form(){
if(document.getElementById('name').value==""){
alert("fill the name") ;
document.getElementById('name').focus();
return false;
}
if(document.getElementById('family').value==""){
alert("fill the family") ;
document.getElementById('family').focus();
return false;
}
if(document.getElementById('username').value==""){
alert("fill the username") ;
document.getElementById('username').focus();
return false;
}
if(document.getElementById('pass').value==""){
alert("fill the pass") ;
document.getElementById('pass').focus();
return false;
}
if(document.getElementById('repass').value==""){
alert("fill the repass") ;
document.getElementById('repass').focus();
return false;
}
if(document.getElementById('q').value==""){
alert("fill the q") ;
document.getElementById('q').focus();
return false;
}
if (document.getElementById('pass').value!=document.g etElementById('repass').value){
alert("not same") ;
document.getElementById('repass').select();
return false;
}
return true;
}
</script>
</head>
<body>
<form action="a.html" method="post" onsubmit="return check_form()">
<table border="1" align="center">
<tr>
<td><input type="text" name="name" id="name" /></td>
<td>نام</td>
<td>*</td>
</tr>
<tr>
<td><input type="text" name="family" id="family"/></td>
<td>فامیلی</td>
<td>*</td>
</tr>
<tr>
<td><input type="text" name="username" id="username"/></td>
<td>نام کاربری</td>
<td>*</td>
</tr>
<tr>
<td><input type="password" name="pass" id="pass" /></td>
<td>رمز</td>
<td>*</td>
</tr>
<tr>
<td><input type="password" name="repass" id="repass" /></td>
<td>تکرار رمز</td>
<td>*</td>
</tr>
<input type="checkbox" id="q" />
<input type="radio" id="e" />
<select>
<option>a</option>
<option>b</option>
</select>
<tr align="center">
<td colspan="3"><input type="reset" value="نوسازی" /><input type="submit" value="ارسال" /></td>
</tr>
</table>
</form>
</body>
</html>