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
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

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.