简体   繁体   English

当我试图阻止多次点击提交时,验证无效

[英]validation not working when i am trying to prevent multiple click on submit

i have used class='required' for required validation which is working fine when i remove onClick="this.form.submit(); this.disabled=true; from submit button. i want to disable multi click with validation 我已经使用class='required'进行必要的验证,当我删除onClick="this.form.submit(); this.disabled=true;来自提交按钮时工作正常。我想禁用多点击验证

<form action="<?php echo $this->url('weeklyplan', array('action' => 'add')); ?>" method="post" id='myform'>
    <div class="mainformdiv">
        <div class= "formelementblock">
            <div class="formelement">
                <select name="txtdefined_week_id" id="txtdefined_week_id" class="select-block required"  onchange="showdateranges()">
                    <option value="">Select Defined Week</option>
                    <?php foreach ($definedweeks as $obj) { ?>
                        <option value="<?php echo $obj->defined_week_id; ?>"><?php echo $obj->start_day . "-" . $obj->end_day; ?></option>
                    <?php } ?>
                </select>
            </div>
        </div>

        <div class= "formelementblock">
            <div class="formelement">
                <input type="text"  readonly="readonly" name="txtstart_date" class="input-text datepickerwidth required" id="txtstart_date" placeholder="Start Date*"/>
            </div>

        </div>
        <div class= "formelementblock last">
            <div class="formelement">
                <input type="text" readonly="readonly"  name="txtend_date" class="input-text datepickerwidth required" id="txtend_date"  placeholder="End Date*"/>
            </div>
        </div>
    </div>

    <div class="clear"></div>
    <div class="form-button">
        <div class="button-block">
            <input onClick="this.form.submit(); this.disabled=true;" class="button" type="submit" name="button" id="button" value="Save" />&nbsp;&nbsp;&nbsp;
            <input class="button" type="button" name="button" id="button" value="Cancel" onclick="window.location = '<?php echo $this->url('weeklyplan', array('action' => 'index')); ?>'" />
        </div>
    </div>
</form>
$(document).ready(function() {
        $("#button").click(function(){
            $('#button').attr('disabled',true);
            $('#myform').submit();
            var no=$("#myform").validate().toShow.length;
            if(no!=0){
                $('#button').attr('disabled',false);
            }

        });
    });

You are using html5 form validation. 您正在使用html5表单验证。 If you want to check if the inputs are valid before submit you have to change the: 如果要在提交前检查输入是否有效,则必须更改:

<input onClick="this.form.submit(); this.disabled=true;" class="button" type="submit" name="button" id="button" value="Save" />

To something like: 对于这样的事情:

<input onClick="checkform(); this.disabled=true;" class="button" type="button" name="button" id="button" value="Save" />

Notice that the button is not a 'submit' type but rather a normal button. 请注意,该按钮不是“提交”类型,而是普通按钮。 With this you can create a javascript function ("checkform()") that checks if the inputs are valid. 有了这个,您可以创建一个javascript函数(“checkform()”)来检查输入是否有效。 There is a function in javascript that returns whether an input with the 'required' html5 attribute is valid. javascript中有一个函数可以返回带有'required'html5属性的输入是否有效。 This function is: 这个功能是:

inputElement.checkValidity()

After you checked if all inputs are valid you can submit the form. 检查所有输入是否有效后,您可以提交表单。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 当单击提交按钮时验证失败时,阻止表单提交 - Prevent form submission when validation fails on submit button click 由于ng-submit无法正常工作,我无法自拔,当我单击它时它将无法运行 - I am stuck thanks to ng-submit not working, it won't run when I click on it 当我多次单击提交按钮时,出现多次错误 - I am getting the error multiple times when I click on the submit button more than once 我正在尝试使用 javascript 进行表单验证,但 email 验证不起作用 - I am trying to make form validation with javascript but email validation not working 当我单击此按钮时,我试图访问以前的状态,但它似乎不起作用 - I am trying to access the previous state when i click this button but it does not seem to be working 我正在执行JavaScript验证,但是当我输入姓氏时它无法正常工作,它不会显示错误并提交表单 - I am doing JavaScript validation but it's not working properly when I enter last name, it does not display error and submit the form 为什么在尝试对列表进行排序时单击按钮时list.js不能正常工作 - Why isn't list.js working when I click the button when I am trying to sort my list 提交单击时出现多个表单验证问题 - Multiple form validation issues on submit click 当我尝试单击shift + tab组合时触发Shift键 - Shiftkey is triggered when I am trying to click the shift + tab combination 当我单击提交表单时,我的javascript函数不起作用 - My javascript function is not working, when i click to submit my form
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM