webwork表单验证
有这样一个webwork表单:
<ww:form action= "register.action " method= "post " id= "register " >
<ww:textfield label= "用户名 " name= "learner.learnername " required= "true " id= "learnername "> </ww:textfield>
<ww:password label= "密码 " name= "learner.learnerpassword " required= "true "> </ww:password>
<ww:textfield label= "email " name= "learner.learneremail "> </ww:textfield>
<ww:submit value= "注册 " onclick= "return validate() ">
</ww:submit>
</ww:form>
其中用户名和密码必填!
我写一个javascript来验证:
<script type= "text/javascript ">
function validate()
{
if(document.register.learnername.value== ' ')
{
alert( "用户名不能为空! ");
return false;
}
if(document.register.learnerpassword.value== ' ')
{
alert( "密码不能为空! ");
return false;
}
return true;
}
</script>
但不起作用!!
------解决方案--------------------通过form的一个属性onSubmit对 "true "或 "false "起作用.所以:
onSubmit= "return validate() "