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

if you have id then used that

  $('is_subscribed').observe('click', function () {

    if($('is_subscribed').checked){
        alert(111);
   }else{
        alert(222);
   }
});
  • As per requirement that solution is ok. But now I am implementing the function as below: – AKSHAYA KUMAR Satapathy Jan 18 '16 at 6:27
  • $$('#is_subscribed')[0].observe('click', function () { if($$('#is_subscribed').checked){ $$('.lblnewsletter').addClassName('chked'); }else{ $$('.lblnewsletter').removeClassName('chked'); } }); – AKSHAYA KUMAR Satapathy Jan 18 '16 at 6:28
  • you are mixing the jquery and prototype. – Qaisar Satti Jan 18 '16 at 6:29
  • But it shows an error "TypeError: $$(...).removeClassName is not a function" – AKSHAYA KUMAR Satapathy Jan 18 '16 at 6:30
  • please solve it – AKSHAYA KUMAR Satapathy Jan 18 '16 at 6:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.