【发布时间】:2015-07-27 20:52:05
【问题描述】:
我有如下图所示的表格,我在其中从查询创建到数据库,每行都有按钮,onclick 将出现提示对话框(我使用 jquery 对话框小部件)
这个 myform html 代码
<form action="prodi_tampil_mhs.php" method="post" name="form_tambah_cl_wisudawan" id="form_tambah_cl_wisudawan">
这是我从查询数据库创建表的 php 代码
while ($fetch_dbsi_mhsw=mysql_fetch_array($query_dbsi_mhsw)) {
$no++;
echo" <tr>
<td>$no</td>
<td>$fetch_dbsi_mhsw[NIM]</td>
<td>$fetch_dbsi_mhsw[Name]</td>
<td style=\"text-align: center;\"><input name=\"bt_tambah_calon_wisudawan\" id=\"bt_tambah_calon_wisudawan\" type=\"image\" src=\"buttonTambah.png\" alt=\"Tambah\" align=\"middle\" width=\"20\" height=\"20\" class=\"bt_tambah_calon_wisudawan\" /></td></tr>";}
还有我的 jquery 代码
$(document).ready(function(){
$(".bt_tambah_calon_wisudawan").click(function(){
var value1 = $(this).closest('tr').find('td:eq(1)').text();
var value2 = $(this).closest('tr').find('td:eq(2)').text();
// Here's the text of the dialog box
var dialog = $("<div style='display: none'><p>Anda akan menambahkan "+value1 + " " + value2 + " sebagai calon wisudawan?</p></div>").appendTo("body");
// This is the button on the form
var form = $("#form_tambah_cl_wisudawan")
// The form button was pressed - open the dialog
$(dialog).dialog({
title: "Konvirmasi Penambahan Data",
dialogClass: "no-close",
width: 600,
modal: true,
buttons: {
"Tambah": function () {
// This will invoke the form's action - putatively deleting the resources on the server
$(form).submit();
$(this).dialog("close");
},
"Cancel": function() {
// Don't invoke the action, just close the dialog
$(this).dialog("close");
}
}
});
return false;
});
});
当我单击对话框中的按钮“tambah”时,表单中的值未通过。我的 jquery 代码有什么错误吗?有什么帮助吗?
【问题讨论】:
-
value1和value2没有做任何事情,最简单的解决方案是在表单中添加 2 个隐藏字段然后设置值 -
我在表单中添加了 2 个隐藏字段但无法正常工作,有没有办法从 jquery 代码中传递值?因为提交按钮如何知道要传递我的行值中的哪一个?
-
设置值如
$("#hiddenFieldIdForValue1").val(value1) -
我在我的 php cde 和 jquery 代码中添加了 hiddenFieldIdForValue1 和 2,但没有任何反应,然后我将表单方法更改为“get”,我在我的 url 中看到了这样的 prodi_tampil_mhs.php?hiddenFieldIdForValue1 =A111002&hiddenFieldIdForValue2=la+imin+lagi%0D%0A++++&hiddenFieldIdForValue1=A111002&hiddenFieldIdForValue2=la+imin+lagi&hiddenFieldIdForValue1=A111003&hiddenFieldIdForValue2=la+imin+lagilagi,所以按钮传递了表中的所有值。我只想要我点击按钮所在行的值。
标签: javascript php jquery html