There is a label (class=lblnewsletter) and checkbox (id=is_subscribed).
When I click on label and if the checkbox is checked the alert will come 111 other wise it return 222.
I have wrote the following code but not working.
Please help.
$$('.lblnewsletter')[0].observe('click', function () {
if($$('#is_subscribed').checked){
alert(111);
}else{
alert(222);
}
});
Qaisar Satti
32.6k18 gold badges88 silver badges138 bronze badges
asked Jan 17, 2016 at 14:03
AKSHAYA KUMAR Satapathy
797 bronze badges
1 Answer 1
if you have id then used that
$('is_subscribed').observe('click', function () {
if($('is_subscribed').checked){
alert(111);
}else{
alert(222);
}
});
answered Jan 18, 2016 at 4:38
Qaisar Satti
32.6k18 gold badges88 silver badges138 bronze badges
-
As per requirement that solution is ok. But now I am implementing the function as below:AKSHAYA KUMAR Satapathy– AKSHAYA KUMAR Satapathy2016年01月18日 06:27:58 +00:00Commented Jan 18, 2016 at 6:27
-
$$('#is_subscribed')[0].observe('click', function () { if($$('#is_subscribed').checked){ $$('.lblnewsletter').addClassName('chked'); }else{ $$('.lblnewsletter').removeClassName('chked'); } });AKSHAYA KUMAR Satapathy– AKSHAYA KUMAR Satapathy2016年01月18日 06:28:33 +00:00Commented Jan 18, 2016 at 6:28
-
you are mixing the jquery and prototype.Qaisar Satti– Qaisar Satti2016年01月18日 06:29:33 +00:00Commented Jan 18, 2016 at 6:29
-
But it shows an error "TypeError: $$(...).removeClassName is not a function"AKSHAYA KUMAR Satapathy– AKSHAYA KUMAR Satapathy2016年01月18日 06:30:20 +00:00Commented Jan 18, 2016 at 6:30
-
please solve itAKSHAYA KUMAR Satapathy– AKSHAYA KUMAR Satapathy2016年01月18日 06:30:47 +00:00Commented Jan 18, 2016 at 6:30
default