[thelist] help me compress this JS function?
Tom Dell'Aringa
pixelmech at yahoo.com
Fri Mar 28 08:50:48 CST 2003
--- Jeff Howden <jeff at jeffhowden.com> wrote:
> oooh, optimizing is fun.
Isn't it though?
<snip original function>
> part of the problem with your current function is that the button's
> value is set for each iteration through the loop. you really
> should only be setting it once.
All I can say on that one is.."oops"...
> also, it seems, based on your function that you're toggling whether
> the checkboxes are checked, and not actually setting all to checked
> or all to [...]
Yes, dernit I noticed that right after I sent this. Normally I would
do this using another checkbox (like on your example) but they don't
want that, just the button. So I can't check the 'checked' value of a
controlling checkbox. Right now I have it changed just to check them
all and not toggle it.
> there's no if. the tertiary operator is used as a statement.
>
> myElement.checked = (matchGroup == cbGroup) ? true : false;
Ahhh I knew I had something wrong.
> or, since the statement (matchGroup == cgGroup) will return a
> boolean already, drop the tertiary operator and reduce it to:
>
> myElement.checked = (matchGroup == cbGroup)
Yes, a good solution!
> i suspect part of the difficulty with your function is that you're
> not naming groups of checkboxes with the same name. if that's the
> case, change that. in order to operate on groups of checkboxes in
> an efficient manner, you really need to have them all share the
> same name.
Ah, I've just looked again at yours. So naming them all the same name
attribute is a good idea? I see you used the ID as the unique
identifier, which makes sense. I will try that instead. Someone else
suggested using the fieldset to check the group, but I think I like
this idea better.
As always Jeff thanks!
Tom
=====
http://www.pixelmech.com/
var me = tom.pixelmech.webDeveloper();
http://www.maccaws.com/
[Making A Commercial Case for Adopting Web Standards]
"That's not art, that's just annoying." -- Squidward
__________________________________________________
Do you Yahoo!?
Yahoo! Platinum - Watch CBS' NCAA March Madness, live on your desktop!
http://platinum.yahoo.com
More information about the thelist
mailing list