正在验证html javascript
Validating html-javascript
当我按下提交按钮时,不会显示错误。我也用过浏览器和谷歌浏览器。
我正在尝试为我的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,这将打开控制台(开发工具),其中提供有关错误的信息。
相关文章:
- Javascript html每点击一次就会更改url
- 通过javascript/html访问twitter共享iframe
- 使用鼠标悬停JavaScript/HTML显示文本
- JavaScript-HTML表单到JSON(空值)和格式
- 使用javascript html实时预览文本区域输入
- 如何每秒从一个变量中提取一定次数的javascript/html
- 使用变量值作为'名称标识符'javascript/html
- JavaScript HTML Onclick
- 非侵入性Javascript HTML注入
- AppendChild Form / Table [Javascript/Html/PHP]
- 按钮don't使用onClick-Javascript HTML重定向
- 在库(javascript/HTML)中将“name”替换为“id”
- 如何确定使用 javascript/html 单击了哪个对象/图像
- 新的javascript HTML元素不遵循css规则
- JavaScript/HTML 错误的解决方案
- 从图像URL javascript html保存图像文件
- javascript html使用webstorage保存表单
- Javascript+HTML中的日期选择器准备好了吗?(需要:DD、MM、YY的单独字段加上日历选择器)
- 谷歌地图/融合表Javascript HTML赢得't显示/可视化所有多边形数据(通过色标)
- JavaScript/HTML命令行小部件