欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

JSP调用JavaScript进行表单验证

程序员文章站 2022-03-01 14:51:50
...

JSP调用JavaScript进行表单验证

<html>
<head>

<script language="JavaScript"> 
function validate(form1)
{
    for (i = 0; i < form1.length; i++){
       if( (form1.elements[i].value == "")){
           alert("You must provide a value for the field named: " +
              form1.elements[i].name)
           return false

           }
        }
        return true
}
</script>
<title>Help Page</title></head><body>
<h2>Please submit your information</h2>

<form action ="jspUsejs.jsp" onSubmit=" return validate(this)">

<table border="0"><tr><td valign="top">

Your name: </td>  <td valign="top">
<input type="text" name="username" size="20">
</td></tr><tr><td valign="top">
Your email: </td>  <td valign="top">
<input type="text" name="email" size="20">
</td></tr>

<tr><td valign="top">
<input type="submit" value="Submit Info"></td></tr>

</table></form>
</body></html>