此代码有什么问题?
网页正在导入此外部JavaScript但是,如果用户输入错误,则不会显示警告消息框。
page.jsp:
<form name="reg-form" action="ServletName"
onsubmit="return validateForm()" method="POST">
<table>
<tr>
<td>
<input name="organization" type="text" required>
</td>
</tr>
<tr>
<td>
<input type="submit" value="Register">
</td>
</tr>
</table>
</form>
val.js:
function validateForm()
{
var result=true;
var message="";
var orgnization=document.forms["reg-form"]["organization"].value;
if(orgnization.length<3)
{
message+="\nName of Organization cannot be less than 3 characters long";
result=false;
}
if(!result)
{
alert(message);
}
return result;
}
答案 0 :(得分:0)
试试这个:
function validateForm()
{
var result=true;
var message="";
var orgnization=document.getElementsByName["organization"][0].value;
if(orgnization.length<3)
{
message +="\n Name of Organization cannot be less than 3 characters long";
result=false;
}
if(!result)
{
alert(message);
}
return result;
}