Reputation: 10824
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
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
Reputation: 145368
$("input[name='rdoSelect']").change(function() {
switch (this.id) {
case "rdoLevel":
// ...
break;
case "rdoBase":
// ...
break;
// etc
}
});
DEMO: http://jsfiddle.net/kQC9L/
Upvotes: 4
Reputation: 382
$("input:radio").click(function () {
var id = $(this).attr("id");
if (id == "rdoLevel" && $(this).is(':checked')) {
//some code
}
});
Upvotes: 2