<script>
function validateForm()
{
var id = document.forms["myForm"]["id"].value;
if ( id % 1 != 0 )
{
alert("Id must be number");
return false;
}
var name = document.forms["myForm"]["name"].value;
if ( name % 1 == 0 )
{
alert("Name must be in alphabets");
return false;
}
var age = document.forms["myForm"]["age"].value;
if ( age % 1 != 0 )
{
alert("Id must be number");
return false;
}
var place = document.forms["myForm"]["place"].value;
if ( place % 1 == 0 )
{
alert("place must be in alphabets");
return false;
}
var choice = document.forms["myForm"]["choice"].value;
if (choice % 1 != 0)
{
alert("Choice must be number");
return false;
}
}
</script>
</head>
<body>
<form action="ui" name="myform" onsubmit="return validateForm()" method="get">
<h2><p align="center"><b>User Management System</b></p></h2><br>
<b>
User ID :
<input type="text" name="id" required>
User Age :
<input type="text" name="age" required>
User Name :
<input type="text" name="name" required>
User Place :
<input type="text" name="place" required>
Enter your choice:
<input type="text" name="choice" required>
<input type="submit" value="Submit">
</b>
</form><b>
我想使用Java脚本验证用户的输入,并且还希望将输入提交到此表单中名为“ui”的servlet名称。但验证没有发生。任何人都可以指导我从单一表格中执行这两项操作吗?
答案 0 :(得分:0)
有一点拼写错误。
<form action="ui" name="myform" onsubmit="return validateForm()" method="get">
在上面的换行myform to myForm
中,它会起作用。