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 开发者_Python百科value in corresponding textbox i.e. with name 'gcno1'......
Please help me with this problem...
.getElementsByName() returns a list, so:
document.getElementsByName('date1')[0].value=String(detail[0]);
精彩评论