javascript - How to access Struct framework ( JSP ) form variable for Ajax query -
please help. have implemented registration form of website using struct framework validation.
<html:form action="servletregister.do" method="post" style="width: 95%"> <tr> <td>user id : * </td> <td><html:text property="userid" /> <html:errors property="userid"/></td> td> <html:button property="button" value="check availability" style="color:#ffffff; background-color: #11bdd1; width: 130px;" onclick="test();" /> <div id="ajax"> // ajax query result show </div> </tr>
problem is, want validate userid using ajax .
function test(){ var userid = document.getelementbyid("userid").value; if(userid=="") { alert("please enter userid"); } else { var xmlhttp = new xmlhttprequest(); xmlhttp.onreadystatechange = function(){ var content = document.getelementbyid("ajax"); content.innerhtml = xmlhttp.responsetext; } //xmlhttp.open("get","table.jsp?num="+num,true); //xmlhttp.send(null); xmlhttp.open("post","validate.jsp",true); xmlhttp.setrequestheader("content-type","application/x-www-form-urlencoded"); xmlhttp.send("userid="+userid); } }
if dont use structs , easy access user id dom object. unable figure out how access struct user id textfield in javascript. please :)
in struts styleid
attribute renders "id" attribute.so change code shown below
<html:text property="userid" styleid="userid" />
reference:http://struts.apache.org/development/1.x/struts-taglib/tlddoc/html/text.html
Comments
Post a Comment