Forums

Checkbox Group Event

Guidonzolo 24 Oct, 2013
Hello,
i've a group of checkboxs built within a "Custom Element" as the following:
<input type="checkbox" class="MyCheck" value="1"/> 
<input type="checkbox" class="MyCheck" value="2"/> 
<input type="checkbox" class="MyCheck" value="3"/>


I want to trigger the change event when click on one of them returning the checkbox selected value.
I've tried so:
$(document).ready(function() {
    $('.MyCheck').click(function() {
        if ($(this).is(':checked')) {
            alert($(this).val());
        }
    });
})


but it stops with error: "Ready is not a function".
If I test the same code on a online JQuery Simulator (such as http://www.w3schools.com/jquery/tryit.asp?filename=tryjquery_hide) it works!

Thanks
Guido
Guidonzolo 25 Oct, 2013
No one helps me?
😢
GreyHead 25 Oct, 2013
Hi Guido,

Is your code running under jQuery or MooTools? The two have confusingly different syntax. ChronoForms uses MooTools and so does Joomla!, though in Joomla! 3 jQuery is also available.

Bob
Guidonzolo 27 Oct, 2013
Hi GreyHead,
I'm within Chronoform and Joomla 2.5 so I presume I'm with MooTools.

Thanks for your support
GreyHead 27 Oct, 2013
Hi Guido,

Then you need to write your script to work with MooTools and this isn't MooTools syntax :-(
$('.MyCheck').click(function() {


Please try something like:
window.addEvent('domready', function() {
  $$('.MyCheck').each( function() {
    this.addEvent('click', function() {
      if ( this.checked ) {
        alert(this.value);
      }
    });
  });
});

Bob
Guidonzolo 01 Nov, 2013
Thanks GreyHead.
🙂
This topic is locked and no more replies can be posted.