Since checkboxes do send their content only when they are checked but my server side script needs ala of them (checked and unchecked fields with values 'Y' or 'N'), I need to dynamically substitute checkbox form fields (their functionalities) with hidden input fields with the same names. So I need jQuery script which will do the following;
- for each checkbox input field on my page it should dynamically insert hidden input field with the same name as checkbox
- it should add onclick listener to all checkbox fields which would set previous hidden field to 'Y' when checkbox is checked, and 'N' otherwise
- remove name of checkbox input field in order to avoid naming conflict when sending form content to server (not sure if this is really needed)
so jQuery should current state:
<input type="checkbox" name="name1" checked="checked" />
<input type="checkbox" name="name2" />
dynamically substitute with:
<input type="hidden" name="name1" value="Y" />
<input type="checkbox" checked="checked" onclick="function()"/>
<input type="hidden" name="name2" value="N" />
<input type="checkbox" onclick="function()"/>
or replace checkbox fields with hidden fields with corresponding values before submitting form.
function() could be noname and dynamically assigned to checkboxes and change previous hidden fields with 'Y' or 'N' according to checkbox state.