StabiloBoss Posted February 27, 2008 Share Posted February 27, 2008 Hi. I have page where I have two dropdown box. When user selects value from dropdown box onchange call function called getData and gives selected value to the function: function getData(Id) { var strURL="finddata.php?Id="+Id; var req = getXMLHTTP(); if (req) { req.onreadystatechange = function() { if (req.readyState == 4) { // only if "OK" if (req.status == 200) { document.getElementById('div1').innerHTML=req.responseText; document.getElementById('div2').innerHTML=req.responseText; } else { alert("There was a problem while using XMLHTTP:\n" + req.statusText); } } } req.open("GET", strURL, true); req.send(null); } } As you can see I have defined two divs, where I want put results which I get from findata.php program document.getElementById('div1').innerHTML=req.responseText; //values to the next dropdown box document.getElementById('div2').innerHTML=req.responseText; //other values to the other div In finddata.php I run two sql-queries. First sql-query finds data which will be put to the next dropdown box second sql-query finds data and I try to put data to the other div-element. The problem is that both data will be set to the div1-element. How I can get data from finddata.php and put data to the two different div-element ? sql-queries are: 1. "SELECT f_id from table where c_name='$id'"; // this data will be set to the next dropdown box 2. "SELECT *FROM other_table; // this data will be set to the page I have defined this two divs (div1 and div2) on the page. Please someone help me. Quote Link to comment Share on other sites More sharing options...
drewbee Posted February 27, 2008 Share Posted February 27, 2008 Try and split your reponse text up with a delimeter IE comma, pipe etc; value1|value2 then with your javascript response = req.responseText.split('|'); element1.innerHTML = response['0']; element2.innerHTML = response['1']; as always, this is psudo code Quote Link to comment Share on other sites More sharing options...
StabiloBoss Posted February 28, 2008 Author Share Posted February 28, 2008 Thanks drewbee. Works like charm! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.