displaying the values in textbox based on AJAX fetched entries
Posted
by Anurag
on Stack Overflow
See other posts from Stack Overflow
or by Anurag
Published on 2010-03-23T22:33:21Z
Indexed on
2010/03/23
22:43 UTC
Read the original article
Hit count: 283
hello,
I've a table in which addition rows can be generatred as per the user need by clicking a javascript function.
Each row has a drop down list, and based on the values of this an AJAX script fetchs some values which has to be displayed in corresponding textfields of the same row..
here is the code for HTML..
<td><div align="center">
<label>
<select name="gcno1" id="gcno1" onchange="fetch_gc(this)">
<option value="0">NIL</option>
<option value="2">1</option>
<?php while($row=mysql_fetch_array($result))
{
?>
<option value="<?php echo $row[0]; ?>"><?php echo $row[0]; ?></option>
<?php }?>
</select>
</label>
</div></td>
<td><div align="center"><input name="date1" id="date1" type="text" size="10" />
</div></td>
and here is the AJAX which I'm writing...
xmlhttp = new XMLHttpRequest();
var value=encodeURIComponent(document.getElementById('gcno1').value);
var parameters="param1="+value;
xmlhttp.open("POST", 'fetch_gc.php', true);
xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlhttp.send(parameters);
xmlhttp.onreadystatechange=function(){
if(xmlhttp.readyState == 4 && xmlhttp.status == 200)
{
var detail=xmlhttp.responseText.split('+');
alert(detail[0]);
document.getElementsByName('date1').value=String(detail[0]);
alert("life " + document.getElementById('gcno1').value);
}
}
The alert inside the AJAX shows the correct response text, detail[0] but is unable to put the value in corresponding textbox i.e. with name 'gcno1'......
Please help me with this problem...
© Stack Overflow or respective owner