[英]Validating html-javascript
當我按下提交按鈕時,錯誤不會顯示。 我也使用過Internet Explorer和谷歌瀏覽器。
我正在嘗試為我的MySQL數據庫執行表單驗證頁面。
也許我的警報代碼是假的?
這是我的代碼:
<html>
<head>
<title>Validare</title>
<script language="JavaScript">
function ver() {
if (document.form1.name.value == "") {
alert("Te rog introdu numele");
return false;
}
If(document.form1.email.value == "") {
alert("Te rog introdu e-mail-ul")
return false;
}
if (document.form1.age.value == "") {
alert("Te rog introdu Varsta");
document.form1.age.focus();
return false;
}
if (document.form1.age.value < 18 || document.form1.age.value > 60) {
alert("Te rog introdu adresa cuprinsa in intevalul[18,60] ");
document.form1.age.focus();
return false;
}
If(document.form1.gender[0].checked == false && document.form1.gender[1].checked == false) {
alert("Te rog alege Sex-ul");
document, form1.age.focus();
return flase;
}
If(docuemnt.form1.limba1.checked == false && document.form1.limba2.checked == false && document.form1.limba3.checked == false) {
alert("Te rog selecteaza cel putin o limba");
return false;
}
if (document.form1.country.value == "") {
alert("Te rog introdu Tara");
document.form1.country.focus();
return false;
}
If(document.form1.myadress.value == "") {
alert("Te rog introdu Adresa");
document.form1.myadress.focus();
return false;
}
if (document.form1.u_name.value == "") {
alert("Te rog introdu Username");
document.form1.u_name.focus();
return false;
}
If(document.form1.pass.value == "") {
alert("Te rog introdu Password")
document.form1.pass.focus();
return false;
}
If(document.form1.pass.value.length < 6) {
alert("Te rog introdu Password mai lunga ca 6");
document.form1.pass.focus();
return false;
}
If(document.form1.r_pass.value == "") {
alert("Te rog introdu din nou parola");
document.form1.r_pass.focus();
terun false;
}
If((document.form1.pass.value) != (document.form1.r_pass.value)) {
alert("Password-ul nu se potriveste");
document.form1.r_pass.value = "";
document.form1.r_pass.focus();
return false;
}
}
</script>
</head>
<body>
<form method="post" action="" name="form1">
<table border="2" align="center" cellpadding="7" cellspacin="7">
<tr>
<td><strong>Nume</strong>
</td>
<td>
<input type="text" name="name" </td>
</tr>
<tr>
<td><strong>E-Mail</strong>
</td>
<td>
<input type="text" name="email">
</td>
</tr>
<tr>
<td><strong>Varsta</strong>
</td>
<td>
<input type="text" name="age" size="2">
</td>
</tr>
<tr>
<td><strong>Sex</strong>
</td>
<td>
<input type="radio" name="gender" value="Male">Masculin
<input type="radio" name="gender" value="Male">Feminin</td>
</tr>
<tr>
<td><strong>Limba</strong>
</td>
<td>
<input type="checkbox" name="limba1" value="Romana">Romana
<input type="checkbox" name="limba2" value="Engleza">Engleza
<input type="checkbox" name="limba3" value="Germana">Germana</td>
</tr>
<tr>
<td><strong>Tara</strong>
</td>
<td>
<select name="country">
<option value="selected">-Selecteaza-
<option value="Germ">Germania
<option value="roman">Romania
<option value="ungar">Ungaria</select>
</td>
</tr>
<tr>
<td><strong>Adresa</strong>
</td>
<td>
<textarea rows="5" cols="20" name="myadress"></textarea>
</td>
</tr>
<tr>
<td><strong>Username</strong>
</td>
<td>
<input type="text" name="u_name">
</tr>
</td>
<tr>
<td><strong>Password</strong>
</td>
<td>
<input type="password" name="pass">
</td>
</tr>
<tr>
<td><strong>Re-Type</strong>
</td>
<td>
<input type="password" name="r_pass">
</td>
</tr>
<tr align="center">
<td>
<input type="submit" value="submit" onClick="return ver(this);">
</td>
<td>
<input type="reset">
</td>
</tr>
</table>
</form>
</body>
</html>
從提交中刪除onclick處理程序並在表單元素上放置一個sumbit處理程序。
<form method="post" action="" name="form1" onsubmit="return ver(this);">
此外,您沒有定義操作,因此不會對服務器端頁面進行發布。 第二個是拼寫錯誤
If(document.form1.r_pass.value == "") {
alert("Te rog introdu din nou parola");
document.form1.r_pass.focus();
terun false; //SHOULD BE return false;
}
If(document.form1.gender[0].checked == false && document.form1.gender[1].checked == false) {
alert("Te rog alege Sex-ul");
document, form1.age.focus();
return flase; //SHOULD be return false;
}
我認為還有更多的拼寫錯誤和其他編碼錯誤。 在瀏覽器中使用鍵盤鍵F12 ,這將打開控制台(開發工具),為您提供有關錯誤的信息。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.