JavaScript 验证 Struts表单的问题
代码如下
<%@ page language= "java " import= "java.lang.* " import= "java.util.* " pageEncoding= "gb2312 "%>
<%@ taglib uri= "http://jakarta.apache.org/struts/tags-bean " prefix= "bean "%>
<%@ taglib uri= "http://jakarta.apache.org/struts/tags-html " prefix= "html "%>
<html>
<head>
<title> JSP for UserLogicForm form </title>
</head>
<body>
<script type= "text/javascript ">
function Yan()
{
alert(document.form.username.value);
}
</script>
<%!
String str;
String ip;
%>
<%
str = new Date().toLocaleString();
ip = request.getRemoteAddr();
%>
<html:form onsubmit= "return Yan() " action= "/userLogic ">
用户名 : <html:text property= "username "/> <html:errors property= "username "/> <br/>
密码 : <html:password property= "userpass "/> <html:errors property= "userpass "/> <br/>
论坛昵称 : <html:text property= "bbsname "/> <html:errors property= "bbsname "/> <br/>
<html:hidden property= "userip " value= " <%= ip%> "/> <html:errors property= "userip "/> <br/>
<html:hidden property= "usertime " value= " <%= str%> "/> <html:errors property= "usertime "/> <br/>
<html:submit value= "注册 "/> <html:cancel value= "取消 "/>
</html:form>
</body>
</html>
不要告诉我用Validator框架验证现在问的是怎么用JS
我的问题是
如何在
function Yan()
{
.....
}
怎样才能点提交获取用户名的值了
------解决方案--------------------function Yan()
{
var obj = document.getElementById( "username ").value;
alert(obj);
}
------解决方案--------------------function Yan()
{
var form=document.forms[0];
alert(form.username.value);
form.submit();
}