Friday, May 17, 2024
 Popular · Latest · Hot · Upcoming
25
rated 0 times [  29] [ 4]  / answers: 1 / hits: 25703  / 10 Years ago, fri, march 21, 2014, 12:00:00

i'm triyng to validate a form.
In this form you've to choose at least one element by checkboxes, and I can't be sure about their quantity (it depends by elements number).
I need to enable the submit input if one or more checkboxes are checked, and disable it if there aren't any checkbox checked, how can I do?
Here's my code:



<form id=booking>
<input type=checkbox name=room1 class=roomselect/>
<input type=checkbox name=room2 class=roomselect/>
<input type=checkbox name=room3 class=roomselect/>
<input type=submit value=Request id=subm />
</form>

More From » jquery

 Answers
5
//dom ready handler
jQuery(function ($) {
//form submit handler
$('#booking').submit(function (e) {
//check atleat 1 checkbox is checked
if (!$('.roomselect').is(':checked')) {
//prevent the default form submit if it is not checked
e.preventDefault();
}
})
})

[#71871] Wednesday, March 19, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
devinjadong

Total Points: 711
Total Questions: 117
Total Answers: 100

Location: Andorra
Member since Sat, May 27, 2023
1 Year ago
devinjadong questions
Thu, Feb 17, 22, 00:00, 2 Years ago
Wed, Dec 8, 21, 00:00, 2 Years ago
Tue, Oct 27, 20, 00:00, 4 Years ago
Fri, Oct 18, 19, 00:00, 5 Years ago
;