I\'m hiding/showing a div based on the state of a checkbox.
You can add a disabled attribute to any fields you don't want to submit.
function toggle_form_element(id) {
if ((document.getElementsByName(id)[0].checked)) {
document.getElementById('sometimesHidden').setAttribute("disabled", "disabled");
} else {
document.getElementById('sometimesHidden').removeAttribute("disabled");
}
}
For a jQuery solution:
// Disables all input, select & textarea tags within the .sometimesHidden div
if(checked) {
$("input, select, textarea", $(".sometimesHidden")).attr("disabled", "disabled");
}
else {
$("input, select, textarea", $(".sometimesHidden")).removeAttr("disabled");
}