Controlling Checkboxes in HTML
Controlling Checkboxes in HTML
Silas asked
354 ●● 1 ●● 6 ●● 17 Feb 22 '12 at 23:01
I think that you can't use number as id, and id must be uniqe. – jcubic Feb 22 '12 at
23:06
1 Just found this. It seems like what you're looking for, with buttons instead of
checkboxes. Make the No preference one name and the others another. The
unchecking of the others would just require their name, and unchecking
No preference would require its name. – chris Feb 22 '12 at 23:07
add a comment
By using our site, you acknowledge that you have read and understand our Cookie
Policy, Privacy Policy, and our Terms of Service.
The elegant solution from jQuery. The "No preference" has "Nop"
1 class, others "pref":
$(document).ready(ffuunnccttiioonn ()
{
$(".Nop").click(ffuunnccttiioonn()
{
iiff ($(tthhiiss).iiss(":checked"))
{
$(".pref").attr("checked", ffaallssee);
}
});
$(".pref").click(ffuunnccttiioonn()
{
iiff ($(tthhiiss).iiss(":checked"))
{
$(".Nop").attr("checked", ffaallssee);
}
});
});
Kath answered
1,689 ●● 12 ●● 15 Feb 23 '12 at 0:40
Thank You! JQuery always works for me. – Silas Feb 23 '12 at 1:00
add a comment
By using our site, you acknowledge that you have read and understand our Cookie
Policy, Privacy Policy, and our Terms of Service.
1. First, you have to give each checkbox a unique ID (currently they
1 all have an ID=1).
2. Then, you would change your "No Preference" checkbox
declaration to this:
lkaradashkov answered
4,871 ●● 1 ●● 11 ●● 12 Feb 22 '12 at 23:11
I kind of get it, still trying to figure it out this way. – Silas Feb 22 '12 at 23:50
add a comment
Your Answer
By using our site, you acknowledge that you have read and understand our Cookie
Policy, Privacy Policy, and our Terms of Service.
Body
Add picture
Log in
OR
Name
By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy
meta chat tour help blog privacy policy legal contact us full site
2019 Stack Exchange, Inc
By using our site, you acknowledge that you have read and understand our Cookie
Policy, Privacy Policy, and our Terms of Service.