php - 单击按钮时从表中获取值

标签 php javascript html

我有一个表,其中显示了一些值。每行都有一个 Order_ID 和一个按钮。

如何在单击按钮时获取 $Order_ID 中的值以显示(警报)?

<tbody>

<?php

foreach($menuextra_result as $transaction)
{
?>
<tr>



$order_id = isset($transaction['order_id'])?($transaction['order_id']) :"";
?>
<?php if($order_id){ ?>
<td><div id="orderID"><?= $order_id ?></a></td>
<?php } else {?>
<td><div ><span style="color:red">MANGLER</span></td>
<?php }?> 



style="color:red">MISSING</span></td>

                        <?php }?>   

//There's more here, but did not bother to show it, because it was irrelevant. 

<td><input type="submit" onclick="getElementById" value="Yes  "></td>
<?php }
?>         

</tr>
<?php
}
?>

</tbody>

这就是我尝试的方法

<script type="text/javascript">
function getElementById()
{
    el = document.getElementById('order_id');
       alert(el);

}
</script>

但是当点击按钮时,没有任何反应

最佳答案

表.php

//assuming you have done you loop work
<table>
<tr>
<td>
<?php echo $row['name']?>
</td>
<td><input type="button" value="click me" onclick="clickMe(<?php echo $row['id']?>)" /></td>
</tr>
</table>

clickme功能是这样的

function clickMe(id) {
alert(id);
}

您将向 clickMe() 函数传递一个参数,该参数是 id

关于php - 单击按钮时从表中获取值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16808538/

相关文章:

php - 如何替换 phpMyAdmin 中的整个表格?

PHP 数据库类模式问题/建议

javascript - 如何将数据传递到 Google 表单中的字段

javascript - 需要像工具提示一样的 html 弹出窗口帮助

javascript - 如何在 DOM 中的键值对中应用样式?

PHP-将表单信息添加到数据库中的现有记录中

javascript - 获取 HTML 或 JavaScript 中的服务器计算机名称

javascript - 禁用一些按钮 TinyMCE

javascript - 如何使用 css 降低 <span> 内容区域的高度?

html - 从使用 Java 脚本进行查询的站点中提取数据