checkbox and set("checked","checked");

1,241 views
Skip to first unread message

snillo

unread,
Apr 10, 2009, 5:56:15 AM4/10/09
to MooTools Users
Hi all,

has someone an idea why this code doesn't work? is this a bug?

var test = new Element("input", {
"type": "checkbox",
"events": {
"click": function(e) {
e.stop();
this.set("checked","checked");
}
}
});
document.body.adopt(test);

if i click on the checkbox then the checkbox isn't checked.

if i call test.set("checked","checked"); not in the onClick Event but
somewhere else, then it works. I tryed this in FF 3.0.8

thanks for help,
Georg

ryan

unread,
Apr 10, 2009, 6:03:54 AM4/10/09
to MooTools Users
have you tried $(e.target).set('checked','checked');

Sebastian Markbåge

unread,
Apr 10, 2009, 6:50:30 AM4/10/09
to MooTools Users
You may want to try the "change" event instead. That should work for
you.

snillo

unread,
Apr 10, 2009, 8:33:01 AM4/10/09
to MooTools Users
Thanks for the fast answers!

ryan youre method works, it's just in the onClick event where set
("checked","checked") doesn't work..

with onChange it works fine, thanks Sebastian.

greetings,
Georg

rpflo

unread,
Apr 10, 2009, 2:49:18 PM4/10/09
to MooTools Users
A while back there was a thread about the 30 ways to set something as
checked with javascript ...

http://groups.google.com/group/mootools-users/browse_thread/thread/9719529fc78e9626

Fábio Costa

unread,
Apr 12, 2009, 11:52:06 AM4/12/09
to mootool...@googlegroups.com
I think onchange for checkboxes and radio buttons is buggy at IE.

http://www.quirksmode.org/dom/events/change.html#t04


Fábio Miranda Costa
Engenheiro de Computação
http://meiocodigo.com

rpflo

unread,
Apr 12, 2009, 3:34:33 PM4/12/09
to MooTools Users
Fabio just jogged my memory.

I actually just ran into this not too long ago also. Having a change
event on checkbox input elements didn't do what it was supposed to in
IE, I had to switch it to a click event.

Whenever a box was checked (or unchecked) I included (or erased) it's
value in (from) an array and sent that data in an ajax request to use
in the query to alter the page results.

(I actually put the click event on the labels of the inputs for some
reason now that I look at the code, go figure ...)



On Apr 12, 9:52 am, Fábio Costa <fabiomco...@gmail.com> wrote:
> I think onchange for checkboxes and radio buttons is buggy at IE.
>
> http://www.quirksmode.org/dom/events/change.html#t04
>
> Fábio Miranda Costa
> Engenheiro de Computaçãohttp://meiocodigo.com
>
> On Fri, Apr 10, 2009 at 3:49 PM, rpflo <rpflore...@gmail.com> wrote:
>
> > A while back there was a thread about the 30 ways to set something as
> > checked with javascript ...
>
> >http://groups.google.com/group/mootools-users/browse_thread/thread/97...

Iain

unread,
Apr 14, 2009, 11:19:58 AM4/14/09
to MooTools Users
its set( 'checked', true / false )

in regular javascript you would do myelement.checked = true / false;
Reply all
Reply to author
Forward
0 new messages