Adding onCheked event to checkbox

Adding onCheked event to checkbox

by Tzahi Zohar -
Number of replies: 1

Hey,

 

I want to add some onChecked event to an elemt.

I added a outside JS to get this event.

what parameters to this do I need to add (if the JS function is called "bye" for say):

$mform->addElement('checkbox','Vpid','Enable Video Point Widegt','',array('id'=> 'CbId'));

 

Thanks!

Average of ratings: -
In reply to Tzahi Zohar

Re: Adding onCheked event to checkbox

by Justin Wyllie -

Hi Tzahi

I think you want something like:

$mform->addElement('checkbox','Vpid','Enable Video Point Widegt','',array('id'=> 'CbId', 'onchange'=>"bye()"));

There is no 'onChecked' event as far as I know.

In your handler you could check for the checked state of the checkbox.

 

function bye() {

If (cb.checked ) {

} else {

}

}

Are you using YUI and doing this in an integrated Moodle way? Another approach would be to bind a listener onto the element in your module.js code. In YUI3 something like:

Y.on('change',yourhandlerreference,'#CbId');

 

Justin