我的代码是这样的,但是就是无法触发验证
<html>
<head>
<script type="text/javascript">
function test(){
var name=document;
var pass=document.form1.passrword.value;
if(name==""||pass=="")
alert("please enter full message!");
}
</script> </head> <body>
<html:form action="index.do" name="form1" styleId="form1" onsubmit="return test()">
<table align=center width=60% border=1>
<tr align=center><td>username</td><td><html:text property="username"></html:text></td></tr>
<tr align=center><td>password</td><td><html:password property="password"></html:password></td></tr>
<tr><td align=right><html:button property="submit" onclick="test()">submit</html:button></td>
<td align=left><html:reset property="reset">reset</html:reset></td>
</tr>
</table>
</html:form>
</body>
</html>
谁能帮我一下,谢了,最好给一个完整的例子
<html>
<head>
<script type="text/javascript">
function test(){
var name=document;
var pass=document.form1.passrword.value;
if(name==""||pass=="")
alert("please enter full message!");
}
</script> </head> <body>
<html:form action="index.do" name="form1" styleId="form1" onsubmit="return test()">
<table align=center width=60% border=1>
<tr align=center><td>username</td><td><html:text property="username"></html:text></td></tr>
<tr align=center><td>password</td><td><html:password property="password"></html:password></td></tr>
<tr><td align=right><html:button property="submit" onclick="test()">submit</html:button></td>
<td align=left><html:reset property="reset">reset</html:reset></td>
</tr>
</table>
</html:form>
</body>
</html>
谁能帮我一下,谢了,最好给一个完整的例子
解决方案 »
- js 取值 只有这些分了,家底都给了
- org.codehaus.xfire.fault.XFireFault: 服务器无法处理请求。 ---> 未将对象引用设置到对象的实例。
- Servlet抛getOutputStream() has already been called for this response异常
- myeclipse 中解决资源文件中文问题
- java.lang.IllegalStateException的问题
- 642633 JSP群,欢迎学习者加入。
- 请问:request.getParameterNames();得到的是不是倒序的?
- 请问apache cxf 如何配置deserializer
- 怎么通过jsp往gb2312的数据库中存进像“垚”、“昇”这样一类的汉字,然后正确的取出来显示在页面上?
- 急,如何建立一张数据库的表,用来储存学生的成绩,但是又要包括这张试卷的各个题目的分数??
- 如何用JAVA语言来表达JavaScript的意思呢?
- jsp表单文本框中输入空格和换行的问题
var pass=document.form1.passrword.value; 你这样写是不对的.
这样试试.
var name=document.forms[0].username.value;
var pass=document.forms[0].passrword.value;
var f = document.form;
var name=f.username.value;
var pass=f.passrword.value;
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"> <head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title> 无标题 1 </title>
<script type="text/javascript" language="javascript"> function test1()
{
if(document.getElementById("txtUserName").value=="")
{
document.getElementById("txtUserName").focus();
alert("notis1");
return false;
}
var filter=/^[.A-Za-z0-9_-]{6,20}$/;
if (!filter.test(document.getElementById("txtUserName").value)){
document.getElementById("txtUserName").focus();
document.getElementById("txtUserName").select();
alert("notis2");
return false;
}
return true;
}
function test2(){
if(document.getElementById("txtUserPass").value=="")
{
document.getElementById("txtUserPass").focus();
alert("notis3");
return false;
} var filter=/^[.A-Za-z0-9_-]{6,20}$/;
if (!filter.test(document.getElementById("txtUserPass").value)){
document.getElementById("txtUserPass").focus();
document.getElementById("txtUserPass").select();
alert("notis4");
return false;
}
return true;
} </script> </head> <body>
用户名: <input type="text" onchange="test1()" name="txtUserName" id="txtUserName"/> <br>
密 码: <input type="text" onchange="test2()" name="txtUserPass" id="txtUserPass"/> <br>
<input type="submit" value="提交" onclick="test1();test2();"/> </body> </html>
1.
使用struts-config.xml中action-mappings标签对应action的name
var name = document.yourActionName.username.value;
var pass = document.yourActionName.password.value;2.
var name = document.forms[0].username.value;
var pass = document.forms[0].password.value;3.
如果name属性不好用,使用html:form标签styleId属性值
var name = document.form1.username.value;
var pass = document.form1.password.value;
<script type="text/javascript">
function test(form){
var name=form.username.value;
var pass=form.passrword.value;
if(name=="" ¦ ¦pass=="")
alert("please enter full message!");
}
</script>
调用的时候
<html:button property="submit" onclick="test(this.form)"> submit </html:button>