[jQuery] Re: Turning a checkbox on and off
Mitchell Waite wrote: I thought the same about checking a checkbox but checked is not the right value, you have to use true and false. So like this: On $(checkbox).attr(checked, true); Off $(checkbox).attr(checked, false); I have no idea why you cant do $(checkbox).attr(checked, checked); This also won't work if( $(checkbox).is(:checked) ) { alert(checked); } Mitch From: jquery-en@googlegroups.com [mailto:[EMAIL PROTECTED] On Behalf Of Ganeshji Marwaha Sent: Sunday, August 05, 2007 1:54 PM To: jquery-en@googlegroups.com Subject: [jQuery] Re: Turning a checkbox on and off To determine if a checkbox is checked, i would use if( $(checkbox).is(:checked) ) { alert(checked); } To check a checkbox, $(checkbox).attr(checked, checked); Both are untested, but let me know how it goes -GTG On 8/5/07, Mitch [EMAIL PROTECTED] wrote: How do you check and uncheck a checkbox from jQuery? And how do you determine if a checkbox has been checked or unchecked? I tried attr and css and none of them worked. Thanks Mitch I hope you will find this helpful http://kawika.org/jquery/cssCheckbox/
[jQuery] Re: Turning a checkbox on and off
Mitchell Waite wrote: Do you know of a good place to learn more about using “:” and all those other characters listed in the docs? http://docs.jquery.com/DOM/Traversing/Selectors http://www.w3.org/TR/2005/WD-css3-selectors-20051215/#pseudo-classes --Klaus
[jQuery] Re: Turning a checkbox on and off
$('your_selector').removeAttr('checked') will also work, which personally seems more intuitive to me. --Erik On 8/5/07, Marshall Salinger [EMAIL PROTECTED] wrote: That is a strange find. I wouldn't have thought to test a different string outside of the html spec for setting it to checked. I guess any value as a string will return true. You can use $('your_selector').attr('checked',''); or attr('checked',false); as you stated, to uncheck the box. Mitchell Waite wrote: Yes that's true it does, but so does $('your_selector').attr('checked','hi mom'); And try unselecting it. *From:* jquery-en@googlegroups.com [mailto:jquery-en@googlegroups.comjquery-en@googlegroups.com] *On Behalf Of *Marshall Salinger *Sent:* Sunday, August 05, 2007 4:06 PM *To:* jquery-en@googlegroups.com *Subject:* [jQuery] Re: Turning a checkbox on and off I am not sure I follow. $('your_selector').attr('checked','checked'); does set a checkbox to checked. -Marshall Mitchell Waite wrote: I thought the same about checking a checkbox but checked is not the right value, you have to use true and false. So like this: On $(checkbox).attr(checked, true); Off $(checkbox).attr(checked, false); I have no idea why you cant do $(checkbox).attr(checked, checked); This also won't work if( $(checkbox).is(:checked) ) { alert(checked); } Mitch *From:* jquery-en@googlegroups.com [mailto:jquery-en@googlegroups.comjquery-en@googlegroups.com] *On Behalf Of *Ganeshji Marwaha *Sent:* Sunday, August 05, 2007 1:54 PM *To:* jquery-en@googlegroups.com *Subject:* [jQuery] Re: Turning a checkbox on and off To determine if a checkbox is checked, i would use if( $(checkbox).is(:checked) ) { alert(checked); } To check a checkbox, $(checkbox).attr(checked, checked); Both are untested, but let me know how it goes -GTG On 8/5/07, *Mitch* [EMAIL PROTECTED] wrote: How do you check and uncheck a checkbox from jQuery? And how do you determine if a checkbox has been checked or unchecked? I tried attr and css and none of them worked. Thanks Mitch
[jQuery] Re: Turning a checkbox on and off
On Aug 6, 5:40 am, Erik Beeson [EMAIL PROTECTED] wrote: $('your_selector').removeAttr('checked') will also work, which personally seems more intuitive to me. --Erik This, indeed seems more correct, as the w3c states: A switch is on when the control element's checked attribute is set... They don't specify set to _what_. (This is a I'd rather unset the attribute than set it to 'false'. This is the method recommended by David Flanagan in his a href=http://safari.oreilly.com/ 0596101996Definitive Guide/a, I believe. -Troy On 8/5/07, Marshall Salinger [EMAIL PROTECTED] wrote: That is a strange find. I wouldn't have thought to test a different string outside of the html spec for setting it to checked. I guess any value as a string will return true. You can use $('your_selector').attr('checked',''); or attr('checked',false); as you stated, to uncheck the box. Mitchell Waite wrote: Yes that's true it does, but so does $('your_selector').attr('checked','hi mom'); And try unselecting it. *From:* jquery-en@googlegroups.com [mailto:jquery-en@googlegroups.comjquery-en@googlegroups.com] *On Behalf Of *Marshall Salinger *Sent:* Sunday, August 05, 2007 4:06 PM *To:* jquery-en@googlegroups.com *Subject:* [jQuery] Re: Turning a checkbox on and off I am not sure I follow. $('your_selector').attr('checked','checked'); does set a checkbox to checked. -Marshall Mitchell Waite wrote: I thought the same about checking a checkbox but checked is not the right value, you have to use true and false. So like this: On $(checkbox).attr(checked, true); Off $(checkbox).attr(checked, false); I have no idea why you cant do $(checkbox).attr(checked, checked); This also won't work if( $(checkbox).is(:checked) ) { alert(checked); } Mitch *From:* jquery-en@googlegroups.com [mailto:jquery-en@googlegroups.comjquery-en@googlegroups.com] *On Behalf Of *Ganeshji Marwaha *Sent:* Sunday, August 05, 2007 1:54 PM *To:* jquery-en@googlegroups.com *Subject:* [jQuery] Re: Turning a checkbox on and off To determine if a checkbox is checked, i would use if( $(checkbox).is(:checked) ) { alert(checked); } To check a checkbox, $(checkbox).attr(checked, checked); Both are untested, but let me know how it goes -GTG On 8/5/07, *Mitch* [EMAIL PROTECTED] wrote: How do you check and uncheck a checkbox from jQuery? And how do you determine if a checkbox has been checked or unchecked? I tried attr and css and none of them worked. Thanks Mitch
[jQuery] Re: Turning a checkbox on and off
How do you check and uncheck a checkbox from jQuery? This is another item that is in the FAQ: http://docs.jquery.com/Frequently_Asked_Questions#How_do_I_check.2Funcheck_an_input.3F --John
[jQuery] Re: Turning a checkbox on and off
To determine if a checkbox is checked, i would use if( $(checkbox).is(:checked) ) { alert(checked); } To check a checkbox, $(checkbox).attr(checked, checked); Both are untested, but let me know how it goes -GTG On 8/5/07, Mitch [EMAIL PROTECTED] wrote: How do you check and uncheck a checkbox from jQuery? And how do you determine if a checkbox has been checked or unchecked? I tried attr and css and none of them worked. Thanks Mitch
[jQuery] Re: Turning a checkbox on and off
Mtich, I like to toggle checkbox states by emulating a click. This allows for any bound events to also trigger. $(:checkbox).click() ~Sean
[jQuery] Re: Turning a checkbox on and off
I thought the same about checking a checkbox but checked is not the right value, you have to use true and false. So like this: On $(checkbox).attr(checked, true); Off $(checkbox).attr(checked, false); I have no idea why you cant do $(checkbox).attr(checked, checked); This also won't work if( $(checkbox).is(:checked) ) { alert(checked); } Mitch From: jquery-en@googlegroups.com [mailto:[EMAIL PROTECTED] On Behalf Of Ganeshji Marwaha Sent: Sunday, August 05, 2007 1:54 PM To: jquery-en@googlegroups.com Subject: [jQuery] Re: Turning a checkbox on and off To determine if a checkbox is checked, i would use if( $(checkbox).is(:checked) ) { alert(checked); } To check a checkbox, $(checkbox).attr(checked, checked); Both are untested, but let me know how it goes -GTG On 8/5/07, Mitch [EMAIL PROTECTED] wrote: How do you check and uncheck a checkbox from jQuery? And how do you determine if a checkbox has been checked or unchecked? I tried attr and css and none of them worked. Thanks Mitch
[jQuery] Re: Turning a checkbox on and off
Sean Well if $(:checkbox).click() works can I say $(:this).click() to check the checkbox? Do you know of a good place to learn more about using : and all those other characters listed in the docs? Mitch PS How do you unclick? From: jquery-en@googlegroups.com [mailto:[EMAIL PROTECTED] On Behalf Of Sean Catchpole Sent: Sunday, August 05, 2007 2:18 PM To: jquery-en@googlegroups.com Subject: [jQuery] Re: Turning a checkbox on and off Mtich, I like to toggle checkbox states by emulating a click. This allows for any bound events to also trigger. $(:checkbox).click() ~Sean
[jQuery] Re: Turning a checkbox on and off
I am not sure I follow. $('your_selector').attr('checked','checked'); does set a checkbox to checked. -Marshall Mitchell Waite wrote: I thought the same about checking a checkbox but checked is not the right value, you have to use true and false. So like this: On $(checkbox).attr("checked", true); Off $(checkbox).attr("checked", false); I have no idea why you cant do $(checkbox).attr("checked", checked); This also wont work if( $(checkbox).is(":checked") ) { alert("checked"); } Mitch From: jquery-en@googlegroups.com [mailto:jquery-en@googlegroups.com] On Behalf Of Ganeshji Marwaha Sent: Sunday, August 05, 2007 1:54 PM To: jquery-en@googlegroups.com Subject: [jQuery] Re: Turning a checkbox on and off To determine if a checkbox is checked, i would use if( $(checkbox).is(":checked") ) { alert("checked"); } To check a checkbox, $(checkbox).attr("checked", "checked"); Both are untested, but let me know how it goes -GTG On 8/5/07, Mitch [EMAIL PROTECTED] wrote: How do you check and uncheck a checkbox from jQuery? And how do you determine if a checkbox has been checked or unchecked? I tried attr and css and none of them worked. Thanks Mitch
[jQuery] Re: Turning a checkbox on and off
Yes that's true it does, but so does $('your_selector').attr('checked','hi mom'); And try unselecting it. From: jquery-en@googlegroups.com [mailto:[EMAIL PROTECTED] On Behalf Of Marshall Salinger Sent: Sunday, August 05, 2007 4:06 PM To: jquery-en@googlegroups.com Subject: [jQuery] Re: Turning a checkbox on and off I am not sure I follow. $('your_selector').attr('checked','checked'); does set a checkbox to checked. -Marshall Mitchell Waite wrote: I thought the same about checking a checkbox but checked is not the right value, you have to use true and false. So like this: On $(checkbox).attr(checked, true); Off $(checkbox).attr(checked, false); I have no idea why you cant do $(checkbox).attr(checked, checked); This also won't work if( $(checkbox).is(:checked) ) { alert(checked); } Mitch From: jquery-en@googlegroups.com [mailto:[EMAIL PROTECTED] On Behalf Of Ganeshji Marwaha Sent: Sunday, August 05, 2007 1:54 PM To: jquery-en@googlegroups.com Subject: [jQuery] Re: Turning a checkbox on and off To determine if a checkbox is checked, i would use if( $(checkbox).is(:checked) ) { alert(checked); } To check a checkbox, $(checkbox).attr(checked, checked); Both are untested, but let me know how it goes -GTG On 8/5/07, Mitch [EMAIL PROTECTED] wrote: How do you check and uncheck a checkbox from jQuery? And how do you determine if a checkbox has been checked or unchecked? I tried attr and css and none of them worked. Thanks Mitch
[jQuery] Re: Turning a checkbox on and off
That is a strange find. I wouldn't have thought to test a different string outside of the html spec for setting it to checked. I guess any value as a string will return true. You can use $('your_selector').attr('checked',''); or attr('checked',false); as you stated, to uncheck the box. Mitchell Waite wrote: Yes thats true it does, but so does $('your_selector').attr('checked','hi mom'); And try unselecting it. From: jquery-en@googlegroups.com [mailto:jquery-en@googlegroups.com] On Behalf Of Marshall Salinger Sent: Sunday, August 05, 2007 4:06 PM To: jquery-en@googlegroups.com Subject: [jQuery] Re: Turning a checkbox on and off I am not sure I follow. $('your_selector').attr('checked','checked'); does set a checkbox to checked. -Marshall Mitchell Waite wrote: I thought the same about checking a checkbox but checked is not the right value, you have to use true and false. So like this: On $(checkbox).attr("checked", true); Off $(checkbox).attr("checked", false); I have no idea why you cant do $(checkbox).attr("checked", checked); This also wont work if( $(checkbox).is(":checked") ) { alert("checked"); } Mitch From: jquery-en@googlegroups.com [mailto:jquery-en@googlegroups.com] On Behalf Of Ganeshji Marwaha Sent: Sunday, August 05, 2007 1:54 PM To: jquery-en@googlegroups.com Subject: [jQuery] Re: Turning a checkbox on and off To determine if a checkbox is checked, i would use if( $(checkbox).is(":checked") ) { alert("checked"); } To check a checkbox, $(checkbox).attr("checked", "checked"); Both are untested, but let me know how it goes -GTG On 8/5/07, Mitch [EMAIL PROTECTED] wrote: How do you check and uncheck a checkbox from jQuery? And how do you determine if a checkbox has been checked or unchecked? I tried attr and css and none of them worked. Thanks Mitch
[jQuery] Re: Turning a checkbox on and off
Thanks for that demo. I see the problem now. When you first stated the idea you presented this to me I missed the : in the $(#check1).is(:checked) part. That is critical. Its one of those things I am not familiar with that makes me so poor at JQ. Anyway I apologize for saying your code did not work. Mitch From: jquery-en@googlegroups.com [mailto:[EMAIL PROTECTED] On Behalf Of Ganeshji Marwaha Sent: Sunday, August 05, 2007 4:33 PM To: jquery-en@googlegroups.com Subject: [jQuery] Re: Turning a checkbox on and off Mitch, I have whipped up a demo page for u... http://www.gmarwaha.com/jquery/jcarousellite/test/testCheckboxChecked.html follow the instructions there. Both the techniques i mentioned initially are working in all 4 major browsers. -GTG On 8/5/07, Mitchell Waite [EMAIL PROTECTED] wrote: Yes that's true it does, but so does $('your_selector').attr('checked','hi mom'); And try unselecting it. From: jquery-en@googlegroups.com [mailto:[EMAIL PROTECTED] On Behalf Of Marshall Salinger Sent: Sunday, August 05, 2007 4:06 PM To: jquery-en@googlegroups.com Subject: [jQuery] Re: Turning a checkbox on and off I am not sure I follow. $('your_selector').attr('checked','checked'); does set a checkbox to checked. -Marshall Mitchell Waite wrote: I thought the same about checking a checkbox but checked is not the right value, you have to use true and false. So like this: On $(checkbox).attr(checked, true); Off $(checkbox).attr(checked, false); I have no idea why you cant do $(checkbox).attr(checked, checked); This also won't work if( $(checkbox).is(:checked) ) { alert(checked); } Mitch From: jquery-en@googlegroups.com [mailto:[EMAIL PROTECTED] On Behalf Of Ganeshji Marwaha Sent: Sunday, August 05, 2007 1:54 PM To: jquery-en@googlegroups.com Subject: [jQuery] Re: Turning a checkbox on and off To determine if a checkbox is checked, i would use if( $(checkbox).is(:checked) ) { alert(checked); } To check a checkbox, $(checkbox).attr(checked, checked); Both are untested, but let me know how it goes -GTG On 8/5/07, Mitch [EMAIL PROTECTED] wrote: How do you check and uncheck a checkbox from jQuery? And how do you determine if a checkbox has been checked or unchecked? I tried attr and css and none of them worked. Thanks Mitch
[jQuery] Re: Turning a checkbox on and off
hey mitch, apology accepted, and there is no need apologize in the first place. I'm happy to help and am glad that i helped resolve ur issue. -GTG On 8/5/07, Mitchell Waite [EMAIL PROTECTED] wrote: Thanks for that demo. I see the problem now. When you first stated the idea you presented this to me I missed the : in the $(#check1).is(:checked) part. That is critical. Its one of those things I am not familiar with that makes me so poor at JQ. Anyway I apologize for saying your code did not work. Mitch *From:* jquery-en@googlegroups.com [mailto:[EMAIL PROTECTED] *On Behalf Of *Ganeshji Marwaha *Sent:* Sunday, August 05, 2007 4:33 PM *To:* jquery-en@googlegroups.com *Subject:* [jQuery] Re: Turning a checkbox on and off Mitch, I have whipped up a demo page for u... http://www.gmarwaha.com/jquery/jcarousellite/test/testCheckboxChecked.html follow the instructions there. Both the techniques i mentioned initially are working in all 4 major browsers. -GTG On 8/5/07, *Mitchell Waite* [EMAIL PROTECTED] wrote: Yes that's true it does, but so does $('your_selector').attr('checked','hi mom'); And try unselecting it. *From:* jquery-en@googlegroups.com [mailto:[EMAIL PROTECTED] *On Behalf Of *Marshall Salinger *Sent:* Sunday, August 05, 2007 4:06 PM *To:* jquery-en@googlegroups.com *Subject: *[jQuery] Re: Turning a checkbox on and off I am not sure I follow. $('your_selector').attr('checked','checked'); does set a checkbox to checked. -Marshall Mitchell Waite wrote: I thought the same about checking a checkbox but checked is not the right value, you have to use true and false. So like this: On $(checkbox).attr(checked, true); Off $(checkbox).attr(checked, false); I have no idea why you cant do $(checkbox).attr(checked, checked); This also won't work if( $(checkbox).is(:checked) ) { alert(checked); } Mitch *From:* jquery-en@googlegroups.com [mailto:jquery-en@googlegroups.comjquery-en@googlegroups.com] *On Behalf Of *Ganeshji Marwaha *Sent:* Sunday, August 05, 2007 1:54 PM *To:* jquery-en@googlegroups.com *Subject:* [jQuery] Re: Turning a checkbox on and off To determine if a checkbox is checked, i would use if( $(checkbox).is(:checked) ) { alert(checked); } To check a checkbox, $(checkbox).attr(checked, checked); Both are untested, but let me know how it goes -GTG On 8/5/07, *Mitch* [EMAIL PROTECTED] wrote: How do you check and uncheck a checkbox from jQuery? And how do you determine if a checkbox has been checked or unchecked? I tried attr and css and none of them worked. Thanks Mitch