jquery对话框小部件未传递我的表单值

时间:2015-07-27 12:15:14

标签: javascript php jquery html

我有像图像bellow的表格,我从查询到数据库创建,每行都有按钮,当onclick将是提示对话框(我使用jquery对话框小部件) image 1

这个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;
    });
 });

出现我的对话框(如图2) image 2

当我点击按钮&#34; tambah&#34;在对话框中,我的值在表单中没有传递。我的jquery代码中的任何错误?有什么帮助吗?

2 个答案:

答案 0 :(得分:1)

$(form).submit();替换为form.submit();,因为您已将选择器$("#form_tambah_cl_wisudawan")存储到var form

答案 1 :(得分:1)

如果您只是通过id选择器和submit()表单引用表单,那么操作将按预期进行。

JS CODE:

 $("#dialog-confirm").dialog({
    resizable: false,
    modal: true,
    title: "Modal",
    height: 250,
    width: 400,
    buttons: {
        "Yes": function () {
            $('#form_tambah_cl_wisudawan').submit();
            $(this).dialog('close');
        },
         "No": function () {
            $(this).dialog('close');
            callback(false);
        }
      }
  });

现场演示@ JSFiddle:http://jsfiddle.net/vvjj8/7506/