Mr.Chowdary Mr.Chowdary - 1 year ago 82
HTML Question

update two divs with one AJAX request?

I'm using AJAX with struts1.x, In my application once select the first select item then second select item will be updated using AJAX. Once i select the second select item it will display the result using AJAX..

Now If the user selects different item of first select items, Then i have to display updated result in Second select items and disappear the previous result caused by second selected item.

Eg. select Country: India

select State: Delhi

Delhi Information will be printed here...

Ajax response

document.getElementById("processStates").innerHTML = xmlHttp.responseText;

document.getElementById("StateInfoDisplay").innerHTML = xmlHttp.responseText;

select country:<select name="countryName"

<span id="processStates"> <select
name="stateName" onchange="showStateInfo(this.value);">

<div id="StateInfoDisplay"></div>

i'm able to implement this. But new requiremetn came.. As per this i have to disappear state information and show states list once he selects some other state.

Next once user select Country as : USA
I have to display all the states of USA and disappear the delhi information.

How to do it?

I'm using only javascript...not jquery..

Laxman Chowdary

Answer Source

Pseudo-code for county click handler:

if (selectedCountry != previousCountry) {

You can do pretty much anything you want in handler - why stop at 2 divs? Rewrite entire page or whatever. If you have some specific problem, post it with your code.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download