i am building an estimates form and I need to send by email only the div's with checked box. how to script it with jquery? I guess I must first get all the checked boxes and unchecked ones and eliminate from the form the correspondent div of the unchecked box.
Asked
Active
Viewed 508 times
3 Answers
2
You can use the :checked
pseudoselector to select checkboxes that are checked:
$("input[type='checkbox']:checked");
Or to get checkboxes that are not checked:
$("input[type='checkbox']:not(:checked)");
Or to get checked checkboxes inside of your correspondent div:
$("#correspondent input[type='checkbox']:checked");
EDIT
So you want divs that have checkboxes, none of which are checked? This will do that
var divsWithoutChecked =
$("div:has(input[type='checkbox'])")
.filter(function () {
return $(this).find("input[type='checkbox']:checked").length === 0
});

Adam Rackis
- 82,527
- 56
- 270
- 393
-
thanks a lot, but actually I need to select the div with no checked boxes and delete them from the form in order to send by email only the selected items – Emilio Yero Jan 02 '12 at 17:02
-
@EmilioYero - Also, I don't think you need to delete unchecked checkboxes from the form -- I'm pretty sure only checked checkboxes' values will post when you submit – Adam Rackis Jan 02 '12 at 17:16
0
to send the email , you need to have a server side page (ASP.NET/ PHP / ASP etc..).. You may check whether the checkbox is checked then make a jQuery ajax call to the server page where you execute the code to send the email.

Shyju
- 214,206
- 104
- 411
- 497
0
See here to get the value of a checkbox: How to retrieve checkboxes values in jQuery
Now, you'll want to do a $.each
on the divs in question, and then make an array out of the ones that you want to send, and then process that array.

Community
- 1
- 1

Dhaivat Pandya
- 6,499
- 4
- 29
- 43