admin管理员组文章数量:1418148
I use Jquery Validation to validate my form.
I have following HTML-form:
<form id="caller">
<label>Phone:</label>
<input type="text" name="phone" id="phonen" class="form-input" value="" />
<div class="option-group check">
<input type="checkbox" name="check1" id="check1" value="1" />
<label for="check1"><p>Need a call</p></label>
</div></form>
Javascript-Code:
<script type="text/javascript">
$(document).ready(function(e) {
$('#caller').validate({
errorPlacement: function(error, element){}
});
});
</script>
If the checkbox is checked, text should get class="form-input validate required".
How can I do this?
I use Jquery Validation to validate my form.
I have following HTML-form:
<form id="caller">
<label>Phone:</label>
<input type="text" name="phone" id="phonen" class="form-input" value="" />
<div class="option-group check">
<input type="checkbox" name="check1" id="check1" value="1" />
<label for="check1"><p>Need a call</p></label>
</div></form>
Javascript-Code:
<script type="text/javascript">
$(document).ready(function(e) {
$('#caller').validate({
errorPlacement: function(error, element){}
});
});
</script>
If the checkbox is checked, text should get class="form-input validate required".
How can I do this?
Share Improve this question asked Dec 14, 2013 at 8:43 user3061007user3061007 572 silver badges4 bronze badges 1- Try first reading the docs before asking: jqueryvalidation/documentation – Hardy Commented Dec 14, 2013 at 8:45
2 Answers
Reset to default 4You can use the depends
$('#caller').validate({
rules:{
phone:{
required: {
depends: function(){
return $('#check1').is(':checked')
}
}
}
}
});
Demo: Fiddle
Add "required" keyword to your element:
<input type="text" name="validate-me" required />
本文标签:
版权声明:本文标题:javascript - Jquery validation if checkbox checked text box gets class="form-input validate required" - Stack 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745278036a2651292.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论