Cant get Java Script code working

zegmis

New Member
Hi Lads,
read a lot about element show/hide functionality and found two great posts
http://fabrikar.com/forums/index.ph...script-code-to-hide-or-show-an-element.30911/
and
http://fabrikar.com/forums/index.ph...ity-of-a-googlemap-element.27260/#post-145919

now based on those i want to write a JS code to show/hide elements based on selected value - usual stuff.
Options to select:
Please select
1
0

so in question 1 (newinjury_table___new_injury_Q1) i have
1. 'On load' action to hide Question 2
PHP:
var q2 = document.getElementById('newinjury_table___new_injury_Q2').findClassUp('fabrikElementContainer');
q2.hide();
This action works ok - element is hidden when form is loaded.

2. 'on change' action to show/hide question 2 based on question 1 selection
PHP:
var test = form_10.formElements.get('newinjury_table___new_injury_Q1').getValue();
var q2 = document.getElementById('newinjury_table___new_injury_Q2').findClassUp('fabrikElementContainer');
 
if(test == 1) {
q2.show();
}
else {
q2.hide();
}
and here nothing happens when question 1 values are changed. Can anybody advise please what i am doing wrong?
elements.pngform.pngq1 element values.png

Thanks,
Paul
 
yep. above code was for fabrik 3.0! for Fabrik 3.1 it should be

PHP:
var radioButton= document.getElementById('copy_paste_your_element_placeholder_for_radio_button').getValue();
var element1= Fabrik.getBlock('form_X').formElements.get('copy_paste_your_element_placeholder_for_element1');
 
if (radioButton=='1')
{
  eleemnt1.show();
}
else if (radioButton=='0')
{
  element1.hide();
}

Found it on http://fabrikar.com/forums/index.php?threads/hide-show-elements-using-custom-javascript.38741/

No i can add plenty of if's and workout questioner workflow. this would save the hassle to work with pre-defined actions.

Cheers,
P
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top