Sirwan Afifi
Sirwan Afifi

Reputation: 10824

check if one item of radio button checked

i have some radio buttons :

<input type="radio" id="rdoLevel" name="rdoSelect" />
<input type="radio" id="rdoBase" name="rdoSelect" />
<input type="radio" id="rdoSchool" name="rdoSelect" />
<input type="radio" id="rdoTypeRegistre" name="rdoSelect" />

and i want to check each item by id,for example i want to check if rdoLevel equal checked some code perform for example like this :

 $("input:radio").click(function () {
                    var id = $(this).attr("id");
                    if (id == "rdoLevel") {
                        //some code
                    }
                });

how can i do this?
thanks in your advise!

Upvotes: 1

Views: 78

Answers (3)

JoeFletch
JoeFletch

Reputation: 3960

Change your click to the following. (The type selector was incorrect.)

$("input[type=radio]").click(function() {
    var id = $(this).attr("id");
    alert(id);

});​

Upvotes: 1

VisioN
VisioN

Reputation: 145368

$("input[name='rdoSelect']").change(function() {
    switch (this.id) {
        case "rdoLevel":
            // ...
            break;
        case "rdoBase":
            // ...
            break;
        // etc
    }
});​

DEMO: http://jsfiddle.net/kQC9L/

Upvotes: 4

atredis
atredis

Reputation: 382

 $("input:radio").click(function () {
                var id = $(this).attr("id");
                if (id == "rdoLevel" && $(this).is(':checked')) {
                    //some code
                }
            });

Upvotes: 2

Related Questions