Anishgiri
01-11-2011, 06:30 AM
What this code does is the table fetch two times. Column Sch_Code has two values which is 13222 and 23333, when I click the SCHCODE column first row value, it display the value which is 13222 on the input text box(that is what it supposed to do), the problem is when I click the second row value it still display 13222 instead of 23333.
ajax
<script type="text/javascript">
function getelem(forms)
{
var TestVar =document.getElementById('sch_code').value;
document.getElementById('sch_code2').value=TestVar ;
if (str=="default value")
{
return false;
}
if (str==null)
{
return false;
}
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("output").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","session_sch.php?q="+str,true);
xmlhttp.send();
}
echo '
<table >
<tr>
<th id="th_style">SCHCODE</th>
</tr>
';
$result=mysql_query($sql);
while($row=mysql_fetch_array($result))
{
echo'
<tr>
<td id="td_style" ><input type="text" size="17" class="inputformat" id="sch_code" value="'.$row['sch_code'].'" onclick="getelem()"></td>
</tr>
';
}
echo ' </table>';
<input type="text" size="17" id="sch_code2">
ajax
<script type="text/javascript">
function getelem(forms)
{
var TestVar =document.getElementById('sch_code').value;
document.getElementById('sch_code2').value=TestVar ;
if (str=="default value")
{
return false;
}
if (str==null)
{
return false;
}
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("output").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","session_sch.php?q="+str,true);
xmlhttp.send();
}
echo '
<table >
<tr>
<th id="th_style">SCHCODE</th>
</tr>
';
$result=mysql_query($sql);
while($row=mysql_fetch_array($result))
{
echo'
<tr>
<td id="td_style" ><input type="text" size="17" class="inputformat" id="sch_code" value="'.$row['sch_code'].'" onclick="getelem()"></td>
</tr>
';
}
echo ' </table>';
<input type="text" size="17" id="sch_code2">