0

I have two scripts in a file active_form.js

The first script hides a text entry when a radiobutton is checked and the second does the same thing when a value is selected in a list.

When there are alone, the both work but together my function GereControleRadio do nothing.

edit : the two scripts are called in the same form.

The code of my scripts :

function GereControleRadio(Controleur, LabelControle, Controle, Masquer) {
    var objLabelControle = document.getElementById(LabelControle);
    var objControle = document.getElementById(Controle);

    if (Masquer=='1') {
        objControle.style.visibility=(objControleur.checked==true)?'visible':'hidden';
        objLabelControle.style.visibility=(objControleur.checked==true)?'visible':'hidden';
    }
    else {
        objControle.disabled=(objControleur.checked==true)?false:true;
        objLabelControle.disabled=(objControleur.checked==true)?false:true;
    }

    return true;
};

function GereControleList(LabelControle, Controle, val) {
    var objLabelControle = document.getElementById(LabelControle);
    var objControle = document.getElementById(Controle);

    if (val != '1% Patronal') {
        objControle.style.visibility='hidden';
        objLabelControle.style.visibility='hidden';
    }
    else {
        objControle.style.visibility='visible';
        objLabelControle.style.visibility='visible';
    }   

    return true;
}; 

The .js is called in my view.yml

And I call the functions :

echo $form['etage']->render(array("onCLick" => "GereControleRadio('logement_etage_Etage', 'numetage_label', 'numetage_form, '1');"))

echo $form['reservataire']->render(array("onChange" => "GereControleList('patronal', 'patronal_form', 'this.value');"))

2 Answers 2

1

I believe you just have 2 functions with conflicting global scope variable names. Try replacing "GereControleList" with this...

function GereControleList(LabelControle, Controle, val) {
    var objLabelControle_ = document.getElementById(LabelControle);
    var objControle_ = document.getElementById(Controle);

    if (val != '1% Patronal') {
        objControle_.style.visibility='hidden';
        objLabelControle_.style.visibility='hidden';
    }
    else {
        objControle_.style.visibility='visible';
        objLabelControle_.style.visibility='visible';
    }   

    return true;
}; 
Sign up to request clarification or add additional context in comments.

1 Comment

I have tried this but I have the same problem : GereControleRadio doesn't work.
0

I have found the error : in GereControleRadio, I have deleted a line.

var objControleur = document.getElementById(Controleur);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.