views:

45

answers:

2

Hello

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');"))
+1  A: 

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;
}; 
I have tried this but I have the same problem : GereControleRadio doesn't work.
Corum
A: 

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

var objControleur = document.getElementById(Controleur);
Corum