Ajax, php populate

hello,

I managed to populate data from database into selectbox using ajax but i could not managed to have the same data in the text area.

Can anybody help me please.



<html>
<head>
<title>Roshan's Triple Ajax dropdown code</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script language="javascript" type="text/javascript">
// Roshan's Ajax dropdown code with php
// This notice must stay intact for legal use
// Copyright reserved to Roshan Bhattarai - nepaliboy007@yahoo.com
// If you have any problem contact me at http://roshanbh.com.np
function getXMLHTTP() { //fuction to return the xml http object
		var xmlhttp=false;	
		try{
			xmlhttp=new XMLHttpRequest();
		}
		catch(e)	{		
			try{			
				xmlhttp= new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch(e){
				try{
				xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
				}
				catch(e1){
					xmlhttp=false;
				}
			}
		}
		 	
		return xmlhttp;
    }
	
	function getState(countryId) {		
		
		var strURL="findState.php?country="+countryId;
		var req = getXMLHTTP();
		
		if (req) {
			
			req.onreadystatechange = function() {
				if (req.readyState == 4) {
					// only if "OK"
					if (req.status == 200) {						
						document.getElementById('statediv').innerHTML=req.responseText;						
					} else {
						alert("There was a problem while using XMLHTTP:\
" + req.statusText);
					}
				}				
			}			
			req.open("GET", strURL, true);
			req.send(null);
		}		
	}
	function getCity(countryId,stateId) {		
		var strURL="findCity.php?country="+countryId+"&state="+stateId;
		var req = getXMLHTTP();
		
		if (req) {
			
			req.onreadystatechange = function() {
				if (req.readyState == 4) {
					// only if "OK"
					if (req.status == 200) {						
						document.getElementById('citydiv').innerHTML=req.responseText;						
					} else {
						alert("There was a problem while using XMLHTTP:\
" + req.statusText);
					}
				}				
			}			
			req.open("GET", strURL, true);
			req.send(null);
		}
				
	}
</script>
</head>
<body>
<form method="post" action="" name="form1">
<table width="600" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td width="150">Country</td>
    <td  width="150">
    
    
    
    <? $countryId=intval($_GET['country']);
$stateId=intval($_GET['state']);
$link = mysql_connect('localhost', 'root', 'emre'); //changet the configuration in required
if (!$link) {
    die('Could not connect: ' . mysql_error());
}
mysql_select_db('db_ajax');
$query="SELECT id, country FROM country ";
$result=mysql_query($query);

?>
<select name="country" onChange="getState(this.value)">
<option>Select City</option>
<? while($row=mysql_fetch_array($result)) { ?>
<option value="<?=$row['id']?>"><?=$row['country']?></option>
<? } ?>
</select>        </td>
    <td  width="150" align="center">State</td>
    <td  width="150"><div id="statediv"><select name="state" >
	<option>Select Country First</option>
        </select></div></td>
    <td  width="150" align="center">City </td>
    <td  width="150"><div id="citydiv"><select name="city">
	<option>Select State First</option>
        </select></div></td>
  </tr>
</table>

<table width="600" align="center">
  <tr>
    <td><label>
      <textarea name="textarea" id="textarea" cols="45" rows="5"></textarea>
    </label></td>
  </tr>
</table>
</form>
</body>
</html>



What did you try?

On the text area I am trying to display what ever i choose on the select box.

example on the select box i have choosen

USA - Newyork - Newyork

I want to display them in the text area aswell.

Thank you very much

I meant, did you actually try anything yet?

document.getElementById(‘statediv’).innerHTML=req.responseText;

That line is updating the element with id=“statediv”. You need to do something similar for any other elements you want to update, eg “textarea”

sorry… i have got no idea about ajax. i know php and it is the first time i am dealing with ajax.

Then you just want someone to write your code for you?

If not you could use a library like jquery (easier than js from scratch to start). Some tutorials are here and ajax api is [URL=“http://docs.jquery.com/Ajax”]here
Or just this

I have a super lightweight ajax thing with demos of what you can do.
http://wlmark.com/ajax_gator.zip

Might be worth trying.