Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/366.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 我在一个页面上有两个按钮,“保存”和“完成”。I';我在为两个输入字段寻找两个不同的警报_Php_Javascript_Jquery_Onbeforeunload - Fatal编程技术网

Php 我在一个页面上有两个按钮,“保存”和“完成”。I';我在为两个输入字段寻找两个不同的警报

Php 我在一个页面上有两个按钮,“保存”和“完成”。I';我在为两个输入字段寻找两个不同的警报,php,javascript,jquery,onbeforeunload,Php,Javascript,Jquery,Onbeforeunload,如果未输入费用金额输入框的值,我将使用onbeforeunload jquery事件通知用户他们未输入金额。输入允许保存的金额后 <td><input type="hidden" name="charge_cc" value="0" class=""> <input type="checkbox" id="charge_cc" name="charge_cc" value="1" checked="" class=""> Charge CC?

如果未输入费用金额输入框的值,我将使用onbeforeunload jquery事件通知用户他们未输入金额。输入允许保存的金额后

<td><input type="hidden" name="charge_cc" value="0" class="">
        <input type="checkbox" id="charge_cc" name="charge_cc" value="1" checked="" class=""> Charge CC? Amount $ <input type="text" id="charge_amt" name="charge_amt" value="523" size="8" maxlength="6"></td>

<script>
$(document).ready(function(){
    $("input[type='text'], select, textarea").change(function(){
        window.onbeforeunload = function()
            {
            return "You have not saved an amount to be charged.";
            }
    });
    $("charge_amt").submit(function(){

        window.onbeforeunload = null;
    });
});
</script>

收抄送费?金额美元
$(文档).ready(函数(){
$(“输入[type='text'],选择,textarea”).change(函数(){
window.onbeforeunload=函数()
{
return“您尚未保存要收费的金额。”;
}
});
$(“费用金额”)。提交(函数(){
window.onbeforeunload=null;
});
});
第二个事件是“完成”按钮

<input type='checkbox' name='reorder_comment_for_CC'> Verify Charge and Leave Comment" ?>
核实费用并留下评论”?>
如果他们点击完成,但未标记此复选框,我想提醒他们,如果不进行验证/检查,他们将无法完成事件

也许我应该使用两个单独的事件,如下所示:

<script type="text/javascript">
$("#charge_amt").keypress(function() {
    if($(this).val().length > 1) {
         return "You have not input an amount to be charged.";
    } else {
         return "Thank you for entering a charge amount, you can now save.";
    }
});</script>

$(“#费用金额”)。按键(功能(){
如果($(this.val().length>1){
return“您尚未输入要收费的金额。”;
}否则{
return“感谢您输入费用金额,您现在可以保存了。”;
}
});

您可以检查用户是否输入了正确的费用值,以及他们是否选中了这样的复选框。您似乎对jQuery语法有点困惑。您应该使用\u元素的\u id\u来查找单个元素。
submit()
事件附在您的表单上,而不是附在
费用\u atm
字段上

$("#id_of_your_form").submit(function() {
    //Here you can check the checkbox
    //This assumes you add the id of the checkbox to be the same as the name
    var $checked = $(this).find("#reorder_comment_for_CC").is(":checked");
    var $validValue = $(this).find("#charge_amt").val().length > 0;        

    if (!$checked) {
       alert("You haven't verified charge");
       return false;//prevent submitting
    }

    if (!$validValue) {
        alert("Invalid value");
        return false;
    }

   return true;

});