组合框值不适用于报价计算器

时间:2013-11-29 09:04:05

标签: javascript

这是我正在使用的代码的一部分,唯一的部分给我带来问题。我正在使用组合框给我Line2_flag和screencharge。没有这段特殊的代码,表单工作正常,所以我知道它就是这个代码片段。任何帮助表示赞赏。谢谢!

<select name="inkcolors" size="1" id="inkcolors" class="FormStyle" 
<option selected value="1">1&lt;/option>
<option value="2">2</option>
<option value="3">3</option>
</select>


var = Line2_flag;
var = screencharge;

if(form.inkcolors[1].selected){
Line2_flag = 1.75;
screencharge = 1;
}

if(form.inkcolors[2].selected){
Line2_flag = 2.25;
screencharge = 2;
}

if(form.inkcolors[3].selected){
Line2_flag = 2.75;
screencharge = 3;
}

1 个答案:

答案 0 :(得分:0)

你可以尝试这种方法:

 <html>
    <form>
        <select name="inkcolors" size="1" id="inkcolors" class="FormStyle" 
    <option selected value="1">1</option>
    <option  value="2">2</option>
    <option value="3">3</option>
    </select>
    </form>

    <script>
        var Line2_flag = null;
    var screencharge = null;
    var field = document.forms[0].elements['inkcolors'];
    var selected = field.options[field.selectedIndex].value;

    if (selected === "1") {
        Line2_flag = 1.75;
        screencharge = 1;
    } else if (selected === "2") {
        Line2_flag = 2.25;
        screencharge = 2;
    } else if (selected === "3") {
        Line2_flag = 2.75;
        screencharge = 3;
    }

    </script>

    </html>