[SOLVED] Js issue | Hide and Show Elements function not working

marcq

Member
Hi,

I have created a form with several fields among others 2 radio button elements.

Each combination of those 2 radio button elements show | hide other elements.

I have used a similar function with another form which is working fine.

No clue why it is not working.

Would appreciate your support.

Cheers, marc


JavaScript:
function doShowHide44() {
    var form = Fabrik.getBlock('form_44');
    var type_rappel = form.formElements.get('gprh_fabrik_user_reminder___type_rappel');
    var no_rappel = form.formElements.get('gprh_fabrik_user_reminder___no_rappel');
    var bloc_contact_cr1 = form.formElements.get('gprh_fabrik_user_reminder___bloc_contact_cr1');
    var bloc_contact_cr2 = form.formElements.get('gprh_fabrik_user_reminder___bloc_contact_cr2');
    var bloc_contact_cr3 = form.formElements.get('gprh_fabrik_user_reminder___bloc_contact_cr3');
    var bloc_contact_fr1 = form.formElements.get('gprh_fabrik_user_reminder___bloc_contact_fr1');
    var bloc_contact_fr2 = form.formElements.get('gprh_fabrik_user_reminder___bloc_contact_fr2');
    var bloc_contact_fr3 = form.formElements.get('gprh_fabrik_user_reminder___bloc_contact_fr3');
    var bloc_tel_contact_cr1 = form.formElements.get('gprh_fabrik_user_reminder___bloc_tel_contact_cr1');
    var bloc_tel_contact_cr2 = form.formElements.get('gprh_fabrik_user_reminder___bloc_tel_contact_cr2');
    var bloc_tel_contact_cr3 = form.formElements.get('gprh_fabrik_user_reminder___bloc_tel_contact_cr3');
    var bloc_tel_contact_fr1 = form.formElements.get('gprh_fabrik_user_reminder___bloc_tel_contact_fr1');
    var bloc_tel_contact_fr2 = form.formElements.get('gprh_fabrik_user_reminder___bloc_tel_contact_fr2');
    var bloc_tel_contact_fr3 = form.formElements.get('gprh_fabrik_user_reminder___bloc_tel_contact_fr3');
... etc

    if (type_rappel == '1' && no_rappel == '1') {

        bloc_contact_cr1.show();
        bloc_contact_cr2.hide();
        bloc_contact_cr3.hide();
        bloc_contact_fr1.hide();
        bloc_contact_fr2.hide();
        bloc_contact_fr3.hide();
        bloc_tel_contact_cr1.show();
        bloc_tel_contact_cr2.hide();
        bloc_tel_contact_cr3.hide();
        bloc_tel_contact_fr1.hide();
        bloc_tel_contact_fr2.hide();
        bloc_tel_contact_fr3.hide();
... etc

    } else if (type_rappel == '1' && no_rappel == '2') {

        bloc_contact_cr1.hide();
        bloc_contact_cr2.show();
        bloc_contact_cr3.hide();
        bloc_contact_fr1.hide();
        bloc_contact_fr2.hide();
        bloc_contact_fr3.hide();
        bloc_tel_contact_cr1.hide();
        bloc_tel_contact_cr2.show();
        bloc_tel_contact_cr3.hide();
        bloc_tel_contact_fr1.hide();
        bloc_tel_contact_fr2.hide();
        bloc_tel_contact_fr3.hide();
... etc

    } else if (type_rappel == '1' && no_rappel == '3') {

        bloc_contact_cr1.hide();
        bloc_contact_cr2.hide();
        bloc_contact_cr3.show();
        bloc_contact_fr1.hide();
        bloc_contact_fr2.hide();
        bloc_contact_fr3.hide();
        bloc_tel_contact_cr1.hide();
        bloc_tel_contact_cr2.hide();
        bloc_tel_contact_cr3.show();
        bloc_tel_contact_fr1.hide();
        bloc_tel_contact_fr2.hide();
        bloc_tel_contact_fr3.hide();
        bloc_introduction_cr1.hide();
        bloc_introduction_cr2.hide();
        bloc_introduction_cr3.show();
        bloc_introduction_fr1.hide();
        bloc_introduction_fr2.hide();
        bloc_introduction_fr3.hide();
        bloc_situation_cr1.hide();
        bloc_situation_cr2.hide();
        bloc_situation_cr3.show();
        bloc_situation_fr1.hide();
        bloc_situation_fr2.hide();
        bloc_situation_fr3.hide();
        bloc_attentes_cr1.hide();
        bloc_attentes_cr2.hide();
        bloc_attentes_cr3.show();
        bloc_attentes_fr1.hide();
        bloc_attentes_fr2.hide();
        bloc_attentes_fr3.hide();
        bloc_politesse_cr1.hide();
        bloc_politesse_cr2.hide();
        bloc_politesse_cr3.show();
        bloc_politesse_fr1.hide();
        bloc_politesse_fr2.hide();
        bloc_politesse_fr3.hide();

    } else if  (type_rappel == '2' && no_rappel == '1') {

        bloc_contact_cr1.hide();
        bloc_contact_cr2.hide();
        bloc_contact_cr3.hide();
        bloc_contact_fr1.show();
        bloc_contact_fr2.hide();
        bloc_contact_fr3.hide();
        bloc_tel_contact_cr1.hide();
        bloc_tel_contact_cr2.hide();
        bloc_tel_contact_cr3.hide();
        bloc_tel_contact_fr1.show();
        bloc_tel_contact_fr2.hide();
        bloc_tel_contact_fr3.hide();
... etc

    } else if (type_rappel == '2' && no_rappel == '2') {

        bloc_contact_cr1.hide();
        bloc_contact_cr2.hide();
        bloc_contact_cr3.hide();
        bloc_contact_fr1.hide();
        bloc_contact_fr2.show();
        bloc_contact_fr3.hide();
        bloc_tel_contact_cr1.hide();
        bloc_tel_contact_cr2.hide();
        bloc_tel_contact_cr3.hide();
        bloc_tel_contact_fr1.hide();
        bloc_tel_contact_fr2.hide();
        bloc_tel_contact_fr3.hide();
... etc

    } else if (type_rappel == '2' && no_rappel == '3') {

        bloc_contact_cr1.hide();
        bloc_contact_cr2.hide();
        bloc_contact_cr3.hide();
        bloc_contact_fr1.hide();
        bloc_contact_fr2.hide();
        bloc_contact_fr3.show();
        bloc_tel_contact_cr1.hide();
        bloc_tel_contact_cr2.hide();
        bloc_tel_contact_cr3.hide();
        bloc_tel_contact_fr1.hide();
        bloc_tel_contact_fr2.hide();
        bloc_tel_contact_fr3.show();
... etc
    }
}

Please access My Fabrik Sites, Site Name GPRH to get more infos.

Thanks a lot in advance for your support.

Cheers, marc
 
What did you select as "Event"?
You can try "click" instead of "change" (or vice versa).
 
Hi troester, thanks for you reply.
I tried with click, change in the Element Javascript. Same result: fields are not shown or hidden.
Javascript code in element calling the function is : doShowHide44();
 
Please access My Fabrik Sites, Site Name GPRH to get more infos.

Those credentials don't work:

Vous ne pouvez pas acc?der ? l'administration de ce site.

I think the problem is

Code:
   var type_rappel = form.formElements.get('gprh_fabrik_user_reminder___type_rappel');
   var no_rappel = form.formElements.get('gprh_fabrik_user_reminder___no_rappel');

... blah blah ...

if(type_rappel =='1'&& no_rappel =='1'){

You are assigning the element object to those variables, then testing them expecting them to be values. Which would need to call getValue() on the object ...

Code:
if(type_rappel,getValue() =='1'&& no_rappel.getValue() =='1'){

... or assign getValue)( to those variables ...

Code:
 var type_rappel = form.formElements.get('gprh_fabrik_user_reminder___type_rappel').getValue();
   var no_rappel = form.formElements.get('gprh_fabrik_user_reminder___no_rappel').getValue();

-- hugh
 
Thank for you reply Hugh, it works fine now. Indeed, I forgot to get the value...
Happy new year, cheers, marc
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top