BILL Carlisle
asked on
Checkboxes - disable all that are in an array or comma delimited list
Hi All,
I want to disable checkboxes that have an id from an array or comma delimited list using JQuery.
Thanks, Bill
I want to disable checkboxes that have an id from an array or comma delimited list using JQuery.
Thanks, Bill
<input id="P2_IERS_0" name="p_v16" value="2901" type="checkbox"><label for="P2_IERS_0">ETP</label></td><td>
<input id="P2_IERS_1" name="p_v16" value="3007" type="checkbox"><label for="P2_IERS_1">AMAI</label></td><td>
<input id="P2_IERS_2" name="p_v16" value="2902" type="checkbox"><label for="P2_IERS_2">AIN</label></td><td>
<input id="P2_IERS_3" name="p_v16" value="2903" type="checkbox"><label for="P2_IERS_3">AT</label></td></tr>
<tr>
<td>
<input id="P2_IERS_4" name="p_v16" value="2904" type="checkbox"><label for="P2_IERS_4">ACW</label></td><td>
<input id="P2_IERS_5" name="p_v16" value="326" type="checkbox"><label for="P2_IERS_5">Auson</label></td><td>
<input id="P2_IERS_6" name="p_v16" value="2905" type="checkbox"><label for="P2_IERS_6">ASW</label></td><td>
<input id="P2_IERS_7" name="p_v16" value="327" type="checkbox"><label for="P2_IERS_7">COAT</label></td></tr>
<tr>
<td>
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
Hi, awesome.. I used the map with function and added a bit more..
$.map(yourArrayOfIDs, function(id, i) {
jQuery('input[id^="P2_IERS _"][value= "'+id+'"]' ).attr("di sabled", true);
})
Now, loading the checkbox, disabling 40 of them, some checked some not, then I as the user changes the ones that are not disabled and saves the form. I want all the checks - enabled or disabled to be saved.
But all the checks of those checkboxes that were disabled were saved as unchecked.
?????????????
$.map(yourArrayOfIDs, function(id, i) {
jQuery('input[id^="P2_IERS
})
Now, loading the checkbox, disabling 40 of them, some checked some not, then I as the user changes the ones that are not disabled and saves the form. I want all the checks - enabled or disabled to be saved.
But all the checks of those checkboxes that were disabled were saved as unchecked.
?????????????
Please post the part of your server side code which saves the checks for your checkboxes. My guess is that something is happening there. Values of disabled form fields are not passed to the backend on form submit, so you may need to take that into account.
An alternative option is to intercept form submit through the onsubmit handler, and then temporarily enable all the disabled checkboxes before submitting for real through JavaScript.
By the way, remember that if it is important that the user be unable to change the value of disabled checkboxes, you need to do separate server-side validation that this is the case, because it is easy for anyone to disable JavaScript.
An alternative option is to intercept form submit through the onsubmit handler, and then temporarily enable all the disabled checkboxes before submitting for real through JavaScript.
By the way, remember that if it is important that the user be unable to change the value of disabled checkboxes, you need to do separate server-side validation that this is the case, because it is easy for anyone to disable JavaScript.
SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
I put debug before it hits my back end process.
no disable
SUPPL[2901:3007:2902:326:3 27:328:325 :331:332:1 47:2908:55 :3009:2909 :333:2910: 2912:2913: 2916:104:2 917:2919:3 012:338:33 9:2920:292 1:340:2924 :2925:341: 2927]
with disable
SUPPL[2901:3007:2902:326:3 27:328:325 :331:332:1 47:2908:55 :3009:2909 :333:2910]
Its not getting the full list.
I use Oracle Apex so may be on their side??
no disable
SUPPL[2901:3007:2902:326:3
with disable
SUPPL[2901:3007:2902:326:3
Its not getting the full list.
I use Oracle Apex so may be on their side??
SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
Yes, I see what you mean.. I have a validation to check in case someone hacked the disabled status but the real solution is to have the backend process absolutely not touch what the user has no access...
Got it! Thanks!
Got it! Thanks!
ASKER
Thx for the help!
$("#"+yourArrayOfIDs.join(
Or if you can get the list_string like "#P2_IERS_1, #P2_IERS_3, #P2_IERS_5",
simply
$(list_string).attr("disab
will do the job.