There is one table that have fields included the add row button. I am using onchange event to call data from other tables, so when I select an option in the option box can automatically get the value that has been selected earlier (do not need input the value manually). Then I add row in the same table and after that I select one option back in the box option and get different values from the first, the problem is the values obtained appear in the first box, not in the second box.
For the html example:
<table id="table">
<tr>
<td>No</td>
<td>Name</td>
<td>Class</td>
<td>Point</td>
<td>Action</td>
</tr>
<tr>
<td>1</td>
<td><select name="name">
<option value="#"> </option>
<?php
opendb();
$query = "SELECT * FROM student";
$result = mysql_query($query);
while($data = mysql_fetch_array($result)){
$ID = $data['ID'];
$Name = $data['Name'];
echo "<option value='$ID'>$Name</option>";
}
?>
</select>
</td>
<td><select name='class' onchange="choosepoint(this);">
<option value="#"> </option>
<?php
opendb();
$query = "SELECT * FROM student2";
$result = mysql_query($query);
while($data = mysql_fetch_array($result)){
$ID1 = $data['ID'];
$class = $data['Class'];
echo "<option value='$ID'>$class</option>";
}
?>
</select>
</td>
<td>
<div id="point" name="point"></div>
</td>
<td><input type="button" value=" + " onClick="addRowToTable();"> | <input type="button" value=" - " onClick="removeRowFromTable();"></td>
</tr>
</table>
the problem I found here:
function choosepoint(combobox)
{
var kode = combobox.value;
if (!kode) return;
xmlhttp.open('get', '../template/get_point.php?kode='+kode, true);
xmlhttp.onreadystatechange = function() {
if ((xmlhttp.readyState == 4) && (xmlhttp.status == 200))
{
document.getElementById("point").innerHTML = xmlhttp.responseText;
}
return false;
}
xmlhttp.send(null);
}
If the ID name "point" changed to "point2" then the value will appear in the second box, but the value in the first box missing.
So I tried looping to get the value of the ID name to be point, point2, point3 etc. (depending on how many want to add the rows).
function choosepoint(combobox)
{
var kode = combobox.value;
if (!kode) return;
xmlhttp.open('get', '../template/get_point.php?kode='+kode, true);
xmlhttp.onreadystatechange = function() {
if ((xmlhttp.readyState == 4) && (xmlhttp.status == 200))
{
Var tbl = document.getElementById("table");
var r = tbl.length;
var i = r;
document.getElementById("point"+ i).innerHTML = xmlhttp.responseText;
}
return false;
}
xmlhttp.send(null);
}
The results I've got is null or no values, cannot run or not get the value to be point, point2, point3 etc.
Anyone can help me?
Thanks.