[英]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" />
<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.