File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to change property of form bean from java script using AJAX

 
Varun Vyas
Greenhorn
Posts: 2
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to change property of a form bean with java script code in ajax.

<html:select property="branch" onchange="validate('currect.do');">
....
....
</html:select>

AJAX function
function validate(url)
{
// For IE
req = new ActiveXObject("Microsoft.XMLHTTP");
if (req)
{
req.onreadystatechange = processStateChange;
req.open("GET", url, true);
req.send();
}
}

According to this url, it directly calls the action 'currect.do'. It is not setting property 'branch' as per selection. What should i do to set this property from java script? Let me know if there is any other way to get this problem solved.
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Varun,
It is not setting property 'branch' as per selection


In JavaScript, an "onchange" event does not change anything, it responds to a change. So, when the user clicks on the "branch" select box and changes the value, it calls your code.

In AJAX, the server-side URL that you call is expected to return XML as output. Does your "currect" action return XML?

Your code indicates that the JavaScript function "processStateChange" is to be called when the response is received from the server. You haven't shown us that function, so we have no idea what it does or if it exists. What it is generally supposed to do is use JavaScript functions to parse the XML returned from the server and then use the Document Object Model (DOM) to change the HTML document in some way.

What should i do to set this property from java script?


I'm afraid I don't have enough information to answer htis. It sounds like you want to change the value in the "branch" select box.. Ok I get that. What do you want to trigger that change? How do you want to change it? from what to what?

Here's my advice: If you're not a strong JavaScript coder, don't bother with the nitty-gritty details of AJAX, but use a framework instead. The one I've used and highly recommend is DWR. Go to the website, download it, and do some of tutorials they suggest, and then try this again using DWR.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic