Re: struts html:form with javascript for ajax
- From: Shashanka.Rao@xxxxxxxxx
- Date: 28 Feb 2007 00:28:58 -0800
On Feb 28, 4:01 am, euneve...@xxxxxxxxxxx wrote:
Hi
I have a struts (1.1) form
<html:form
<html:text
<html:text ...
</html:form>
All was well until I wanted to add an ajax field that would do auto-
complete.
Previously working example had
<input id="complete-field"
This was incompatible with the html:form tag and so I continued to use
<input
but when I submit the form the value of the input field is null
How can I modify my form so that I can use the javascript
functionality ?
Thanks
Using Ajax you will be passing all the request parameters through GET
and the there is no form.submit() happening. This may be one of the
reasons. In that case only way to send these parameters is to build
the URL string with the request parameters. Look at the code below to
build your URL.
function retrieveURL(url,nameOfFormToPost) {
//convert the url to a string
url=url+getFormAsString(nameOfFormToPost);
//Do the AJAX call
if (window.XMLHttpRequest) {
// Non-IE browsers
req = new XMLHttpRequest();
req.onreadystatechange = processStateChange;
try {
req.open("GET", url, true);
} catch (e) {
alert("Server Communication Problem\n"+e);
}
req.send(null);
} else if (window.ActiveXObject) {
// IE
req = new ActiveXObject("Microsoft.XMLHTTP");
if (req) {
req.onreadystatechange=processStateChange;
req.open("GET", url, true);
req.send();
}
}
}
getFormAsString() is a "private" method used by the retrieveURL()
method. This will get all the form Elements and appends to the URL
function getFormAsString(formName){
//Setup the return String
returnString ="";
//Get the form values
formElements=document.forms[formName].elements;
//loop through the array, building up the url
//in the format '/strutsaction.do&name=value'
for(var i=formElements.length-1;i>=0; --i ){
//we escape (encode) each value
returnString+="&"
+escape(formElements[i].name)+"="
+escape(formElements[i].value);
}
//return the values
return returnString;
}
.
- References:
- struts html:form with javascript for ajax
- From: eunever32
- struts html:form with javascript for ajax
- Prev by Date: element4solution
- Next by Date: Re: World Ultimate fighting
- Previous by thread: Re: struts html:form with javascript for ajax
- Next by thread: New Feature to try by Google
- Index(es):
Relevant Pages
|