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);
   }
});

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);
   }
});
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

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.