this is how radio buttons should work..
So Andy thinks that radio buttons should turn off when you click on the selected one again… and after playing with this a bit, it’s kind of intuitive…
Pretty cool, eh? To get radio buttons to kind of work like checkboxes, here’s what I had to do..
First, since the onClick event always evaluates a radio button to “checked” when the radio button was unchecked or checked before you clicked (which is a little weird, but I guess it makes sense since any function you call with onClick happens *after* the click, and therefore .checked would evaluate to true) — anyway, I put an onFocus to set the “ischecked” variable, and then used that to determine whether or not to turn the radio button back off…
so, add:
onFocus="javascript:woop(this);" onClick="javascript:woot(this);"
to all the radio buttons… and then add the javascript functions:
function woop(radiobutton) {
ischecked = radiobutton.checked;
}
function woot(radiobutton) {
if (ischecked) {
radiobutton.checked = false;
ischecked = false;
} else {
ischecked = true;
}
}
W00t! Maybe there’s a simpler way to do this, and if there is, lemme know. Happy Geeky Friday.
February 19th, 2006 at 11:26 am
doesn’t work in safari.
February 20th, 2006 at 3:45 pm
hmm next time i’m a on safari…i’ll make sure not to pack those radio buttons.
March 2nd, 2006 at 10:01 pm
function woot(radiobutton) {
radiobutton.checked = !ischecked;
ischecked = !ischecked;
}
Not sure which is more efficient. Thoughts?
Thanks for the mind-candy!
March 6th, 2006 at 11:38 am
Sure.. i think yours works too, and yes, less lines, but it’s a little hard to read, imho.. i’m dumb and i like my logic spelt out for me..