• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

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

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic