Exemple of javascript Code to hide or show an element

ThierryM

Member
Hi everybody and Happy New Year too,
For helping and because I searched a lot, this is an exemple of javascript code. In this way, you have more possibilities and you can adjust more precisely what you want than using the GUI (besides, because of lot of events, I didn't succeed to have a good working with the GUI : inherit problems ...).

So I put this code for a radiobutton element event "click" for a Fabrik form (version 3.0.63) in Joomla! 2.5.8, in order to hide/show (source : http://fabrikar.com/forums/showthread.php?p=145919#post145919) others elements and change elements values.

Code:
//To get the value of the elements
 var forfait = form_3.formElements.get('pre_inscriptions___Choix_du_forfait').getValue();
 var nuitmardi = form_3.formElements.get('pre_inscriptions___nuitmardi').getValue();
 var repasdimanche = form_3.formElements.get('pre_inscriptions___repasdimanche').getValue();
 var piquenique = form_3.formElements.get('pre_inscriptions___nuitmardi').getValue();

 // To get the elements containers in order to show/hide them  
 var elemardi = document.getElementById('pre_inscriptions___nuitmardi').findClassUp('fabrikElementContainer');
 var elepiquenique = document.getElementById('pre_inscriptions___piquenique').findClassUp('fabrikElementContainer');

 // Processing
if (forfait==170) {
    form_3.formElements.get('pre_inscriptions___nuitmardi').update('0');
 form_3.formElements.get('pre_inscriptions___repasdimanche').update('1');
    elemardi.hide();
    elepiquenique.show();
 } else if (forfait==150) {
 form_3.formElements.get('pre_inscriptions___repasdimanche').update('0');
    elemardi.show();
    elepiquenique.hide();
 } else if (forfait==320) {
 form_3.formElements.get('pre_inscriptions___repasdimanche').update('1');
     elemardi.show();
     elepiquenique.show();
 }
I hope this could help. Regards,

Thierry
 
What an awesome post! With references and everything. I spent an hour playing with this based on the WIKI and I would have never guessed to call the containing document. Thank you for saving me lots of time!
 
We are in need of some funding.
More details.

Thank you.

Members online

No members online now.
Back
Top