code for hiding / showing elements from checkbox selection

enzo2016

Member
Hello,
I would need a sample javascript code for hiding /showing some elements or groups after checking or unchecking a checkbox.
Please could you suggest a sample code or a page where learning?

Thank you very much for the help,

Enzo
 
You can either do it using the built in events handling, using the "contains" condition, so a seperate event for each value you want to check and process for.

Or you can roll your own function in a form_X.js file, and check the values yourself ...

Code:
function doMyThing(el) {
   // value of a checkbox will be an array
   var v = el.getValue();
   // check for each value you need to process for ...
   if (jQuery.inArray('1', v) !== -1) {
      el.form.formElements.get('yourtable___someelement').hide();
      el.form.formElements.get('yourtable___somothereelement').show();
   }
   else if (jQuery.inArray('2', v) !== -1) {
      el.form.formElements.get('yourtable___someelement').show();
      el.form.formElements.get('yourtable___somothereelement').show();
   }
   // add more 'else if' as required
}

Then in the JS events for you checkbox, on "click", do ...

doMyThing(this);

-- hugh
 
Thanks so much Hugh,
about the groups, what is the code for hiding / showing them?
That is the code to replace the following lines:
el.form.formElements.get('yourtable___someelement').hide();
el.form.formElements.get('yourtable___somothereelement').show();

Thanks,

-- Enzo
 
Just use a straight jQuery hide/show ...

Code:
jQuery('#group123').hide();

... where 123 is the numeric ID of the group.

-- hugh
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top