2

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

1 Answer 1

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
7
  • As per requirement that solution is ok. But now I am implementing the function as below: Commented Jan 18, 2016 at 6:27
  • $$('#is_subscribed')[0].observe('click', function () { if($$('#is_subscribed').checked){ $$('.lblnewsletter').addClassName('chked'); }else{ $$('.lblnewsletter').removeClassName('chked'); } }); Commented Jan 18, 2016 at 6:28
  • you are mixing the jquery and prototype. Commented Jan 18, 2016 at 6:29
  • But it shows an error "TypeError: $$(...).removeClassName is not a function" Commented Jan 18, 2016 at 6:30
  • please solve it Commented Jan 18, 2016 at 6:30

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.