I have a form I'm working on with a bunch of checkboxes. Some of the checkboxes are checked via php before the document is loaded. I am trying to identify if the user checks a checkbox that was not already checked from the php script.
If they check one of the unchecked checkboxes I want to show a div that contains a textarea where they can add additional details.
So far I'm thinking the best direction to go is to store the value and status of all the checkboxes into an array. Status of checked is stored as 1 and status of unchecked is stored as 0.
Each time a checkbox is clicked a new array gets created that contains the value and status of all the checkboxes. Then is is compared to the original array. If a new checked off checkbox is identified during the compare then show the div with the textarea in it.
I am wondering if anyone knows how to do something like this or is there a better way to accomplish what I am looking to do?
HTML:
<label><input type='checkbox' class='supress' name='suppressList[]' value='background' /></label>
<label><input type='checkbox' checked='checked' class='supress' name='suppressList[]' value='refsComp' /></label>
<label><input type='checkbox' class='supress' name='suppressList[]' value='I9' /></label>
<textarea id='details' name='additionalDetails'></textarea>
jQuery:
var status = $('input[type="checkbox"]').filter('.supress').map(function(){
var value = $(this).attr('value');
if($(this).is(':checked'))
return { 'value':value, 'status' : 1};
else
return { 'value':value, 'status' : 0};
});
Aucun commentaire:
Enregistrer un commentaire