Javascript:根据 Select 菜单的值使用变量填充文本字段的值

Javascript: Populate value of Text Fields with Variables based on Value of Select Menu

HTML:

<select id="SHIELD" onchange="calcCHO();" >
                                <option  value="610" selected >CHO-SHIELD 610</option>
                                <option  value="608" >CHO-SHIELD 608</option>
                                <option  value="604" >CHO-SHIELD 604</option>
                            </select>

    <input id="FILLER" type="text" disabled  value="" />

脚本:

    function calcCHO(){
var f_S = "Silver";
var f_N = "Nickel";
var f_SC = "Silver/Copper";
        
var CHOS = document.getElementById("SHIELD").value;
var FILLER = document.getElementById("FILLER").value;

if(CHOS === "610") { 
        FILLER = f_S;   
    }
    else if (CHOS === "608") { 
        FILLER = f_N;   
    }   
    else { 
        FILLER = f_SC;  
    }       
}

这看起来很简单,知道为什么它不起作用或产生任何控制台错误吗?

谢谢!

试试吧。

函数 calcCHO(){

var f_S = "Silver";
var f_N = "Nickel";
var f_SC = "Silver/Copper";

var CHOS = document.getElementById("SHIELD").value;
var FILLER = document.getElementById("FILLER");

if(CHOS === "610") {
    FILLER.value = f_S;
}
else if (CHOS === "608") {
    FILLER.value = f_N;
}
else {
    FILLER.value = f_SC;
}

}