开发者

Two scripts Javascript doesn't work together

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, v开发者_开发百科al) {
    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');"))


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 found the error : in GereControleRadio, I have deleted a line.

var objControleur = document.getElementById(Controleur);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜