Re: struts html:form with javascript for ajax



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;
}

.



Relevant Pages

  • Re: How to display page while long-running process executing?
    ... I was able to get the 3rd option (ASP.NET AJAX) pattern working for a simple ... For some reports, this generating/rendering of the report can take maybe 20 ... string format = outputformat; ... Microsoft MSDN Online Support Lead ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: AJAX question
    ... Basically, I set the title, set the array, and then invoke the send method which sets the headers and echoes the result of the string of headers and body that I have built. ... When I try to use it with AJAX involved, using ob_start and ob_get_contents, it simply gets printed to the screen. ... That AJAX stuff is working properly for everything else and returning proper strings that are displayed properly. ...
    (comp.lang.php)
  • Re: AJAX question
    ... Jerry Stuckle wrote: ... Basically, I set the title, set the array, and then invoke the send method which sets the headers and echoes the result of the string of headers and body that I have built. ... When I try to use it with AJAX involved, using ob_start and ob_get_contents, it simply gets printed to the screen. ...
    (comp.lang.php)
  • Re: AJAX question
    ... Basically, I set the title, set the array, and then invoke the send method which sets the headers and echoes the result of the string of headers and body that I have built. ... When I try to use it with AJAX involved, using ob_start and ob_get_contents, it simply gets printed to the screen. ... That AJAX stuff is working properly for everything else and returning proper strings that are displayed properly. ...
    (comp.lang.php)