Jump to content

how to set data to div-elements


StabiloBoss

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/93368-how-to-set-data-to-div-elements/
Share on other sites

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

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.