获取对话框值以确定是否提交表单

时间:2013-09-04 06:31:48

标签: javascript forms jquery-ui return-value

我有一个这样的表格:

<form action="confirm-and-send.php" method="post" onsubmit="return(confirmation());">
    <input a lot of input fields here>
    <button type="submit" name="confirm_and_send" id="submit-button"  class="sent-to-client-bttn" style="margin-left:630px;margin-top: -125px;"></button>
</form> 

然后我有jquery ui功能

function confirmation(){
   $("#some-div").dialog({
        bgiframe: true,
        autoOpen: false,
        minHeight: 200,
        width: 350,
        modal: true,
        closeOnEscape: false,
        draggable: false,
        resizable: false,
        buttons: {
                'Yes': function(){
                    $(this).dialog('close');
                    callback(true);
                },
                'No': function(){
                    $(this).dialog('close');
                    callback(false);
                }
            }
    });
}
function callback(value){
     //do something
}

我正在关注他们所说的herehere,但它对我不起作用。如果我放event.preventDefault(),则yes按钮不会提交for;如果我没有提交表格,我选择任意两个选项之前。任何人都能给我一个恰当的例子吗?

2 个答案:

答案 0 :(得分:0)

我认为您正在使用JqueryUi对话框..它不起作用..为此您必须使用this

我向你解释当你点击时会发生什么..

它不会停止你的点击..它会自动提交...所以你必须尝试default..browser确认

答案 1 :(得分:0)

在表单外面按下按钮。

<form action="" method="post" id="my_form" onsubmit="">
        <input type="text" name="x"/>

    </form> 
    <button name="confirm_and_send" id="submit-button" value="Submit" class="sent-to-client-bttn" onclick="confirmation();">Submit</button>
    <div id="some-div" style="display:none">Hi</div>


function confirmation(){


   $("#some-div").dialog({
        bgiframe: true,
        minHeight: 200,
        width: 350,
        modal: true,
        closeOnEscape: false,
        draggable: false,
        resizable: false,
        buttons: {
                'Yes': function(){
                    $(this).dialog('close');
                    callback(true);
                },
                'No': function(){
                    $(this).dialog('close');
                    callback(false);
                }
            }
    });


}
function callback(value){
     alert(value);
}