Tuesday, March 4, 2008

Checkbox Checkboxes jQuery HOWTO Learning

Checkboxes support in jQuery are one consistent FAQ item that I see asked about (and have asked about myself quite a few times)

Here is a quick DL on the subject.. Taken from the style found in "Learning jQuery" getting an DOM object reference is as easy as the following line of JS code.

var chkIsIntelPerson = $("#chkIsIntelPerson").get(0);

This provides a handle to the HTML DOM Checkbox Object (W3Schools )with which you can access all of it's properties.

You can also bind a jQuery click event that will not mess with the toggle of the object

$("#chkIsIntelPerson").click( function(){

if (chkIsIntelPerson.checked)

$txtSecurityRoles.val("INTRNLGNRLUSR");

else

$txtSecurityRoles.val("");

});

The $txtSecurityRoles is a style of sytax from Learning jQuery that I like and represents a jQuery object where as the chkIsIntelPerson is just a normal HTML DOM object.

Please visit the W3Schools site and see all about the Ceckbox object there

I hope this helps.

Kevin Pirkl

No comments:

Blog Archive