[英]Get data from <td> on the same table row specified by row id and perform computation
I have an html table populated by data coming from a mysql database. 我有一个html表,其中填充了来自mysql数据库的数据。 This is the structure:
结构如下:
<table>
<?php
foreach($prods as $key=>$p){
?>
<tr class="row1" id="tr<?php echo $p['ProductID']?>">
<td id="pid<?php echo $p['ProductID']?>"><?php echo $p['ProductID']?></td>
<td id="pname<?php echo $p['ProductID']?>"><?php echo $p['ProductName'];?></td>
<td id="pdesc<?php echo $p['ProductID']?>"><?php echo $p['ProductDesc'];?></td>
<td id="pprice<?php echo $p['ProductID']?>"><?php echo $p['UnitPrice'];?></td>
<td><input type="checkbox" id="chk<?php echo $p['ProductID']?>" checked></td>
<td><input type="text" style="width:50px;" onkeyup="getall(this);" id="<?php echo $p['ProductID']?>"></td>
<td><input type="text" style="width:50px;" id="total<?php echo $p['ProductID']?>"> </td>
<span id="ttl" name="ttl"> 0.00</span>
</tr>
<?php
}
?>
</table>
I don't have issues populating the table, however I need to update the <span id="ttl">
value, every time the user changes the value of the <input type="text" style="width:50px;" onkeyup="getall(this);" id="<?php echo $p['ProductID']?>"></td>
我没有问题填充表格,但是每次用户更改
<input type="text" style="width:50px;" onkeyup="getall(this);" id="<?php echo $p['ProductID']?>"></td>
值时,我都需要更新<span id="ttl">
值<input type="text" style="width:50px;" onkeyup="getall(this);" id="<?php echo $p['ProductID']?>"></td>
<input type="text" style="width:50px;" onkeyup="getall(this);" id="<?php echo $p['ProductID']?>"></td>
<input type="text" style="width:50px;" onkeyup="getall(this);" id="<?php echo $p['ProductID']?>"></td>
. <input type="text" style="width:50px;" onkeyup="getall(this);" id="<?php echo $p['ProductID']?>"></td>
。 I made a Javascript function but I fail doing what I want. 我做了一个Javascript函数,但是我做不到我想要的。
The value of the span should be the product of <td id="pprice<?php echo $p['ProductID']?>"><?php echo $p['UnitPrice'];?></td>
and the quantity entered by the user at the textbox. 范围的值应为
<td id="pprice<?php echo $p['ProductID']?>"><?php echo $p['UnitPrice'];?></td>
用户在文本框中输入的数量。
I will soon save these data back into the database once all fields are filled. 填写完所有字段后,我很快会将这些数据保存回数据库中。
Not sure if this is used correctly. 如果这是正确使用不知道。 Just try something like:
只需尝试类似:
<input type="text" style="width:50px;" onkeyup="getall('<?php echo $p['ProductID']?>');" id="<?php echo $p['ProductID']?>"></td>
And in your javascript function: 并在您的javascript函数中:
function getall(strId)
{
var tmpObj = document.getElementById(strId);
alert("reported id for testing: " + tmpObj.getAttribute("id"));
}
Try that. 试试看
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.