Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/88.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 尝试将下拉框中的选项中的值和文本添加到表中,但我不能添加多个?_Javascript_Html_Combobox_Row_Inputbox - Fatal编程技术网

Javascript 尝试将下拉框中的选项中的值和文本添加到表中,但我不能添加多个?

Javascript 尝试将下拉框中的选项中的值和文本添加到表中,但我不能添加多个?,javascript,html,combobox,row,inputbox,Javascript,Html,Combobox,Row,Inputbox,好吧,这很难解释,但基本上我有一个下拉框,它是用javascript创建的,带有window.onload函数。在选项一的下拉框中,值为100,名称为blueprint one,第二个选项称为blueprint II,值为200。然后我选择它,然后用一个输入框来选择我想要的数量,这个输入框调用函数来做一些计算,删除下拉框前面的任何行,并用正确数量的blueprint one替换它!因此,如果您选择blueprint one中的5,它将如下所示: 蓝图一*5 | 500 而不是: 蓝图一| 100

好吧,这很难解释,但基本上我有一个下拉框,它是用javascript创建的,带有window.onload函数。在选项一的下拉框中,值为100,名称为blueprint one,第二个选项称为blueprint II,值为200。然后我选择它,然后用一个输入框来选择我想要的数量,这个输入框调用函数来做一些计算,删除下拉框前面的任何行,并用正确数量的blueprint one替换它!因此,如果您选择blueprint one中的5,它将如下所示:

蓝图一*5 | 500 而不是: 蓝图一| 100 蓝图一| 100 蓝图一| 100 蓝图一| 100 蓝图一| 100

但我遇到的问题是当我要换成蓝图二的时候!现在让我们假设我想要2个蓝图2和5个蓝图1,所以我在输入框中选择2,所以我想要发生的是:

蓝图一*5 | 500 蓝图二*2 | 400

真正发生的是:

蓝图二*2 | 400

它删除了蓝图一,并替换为蓝图二,但我想要两者! 代码在下面,谢谢! JavaScript:

//function that is activated when the input box is increased/decreased
function bluePRTfunc(userVal)
{
    //userVal is getting (this) from the input box in the html
    userValVal = userVal.value;

    var table = document.getElementById('tableFull');
    //getting selected blueprint
    var selectedBp = document.getElementById("Blueprints");
    var bPText = selectedBp.options[selectedBp.selectedIndex].text;
    var bPValue = selectedBp.options[selectedBp.selectedIndex].value;
    //setting the value of the blueprint by multiplying it with the input value
    bPValue = bPValue * userValVal;
    // making the name of the blueprint have a *  and then the number of times the user has selected
    bPTextFinal = bPText +" * " + userValVal;
    //  for loop to go through the rows of the table
    for (var i = 1, row; row = table.rows[i]; i++) {
        //getting cost that is in the table
        var subtractCost = table.childNodes[3].childNodes[i].childNodes[1].childNodes[1].innerHTML;
        //getting name that is in the table
        var subtractName = table.childNodes[3].childNodes[i].childNodes[0].childNodes[0].innerHTML;
        //getting row that is in the table
        var tee = table.childNodes[3].childNodes[i].rowIndex;


        //deleting the row that is already there
        document.getElementById("tableFull").deleteRow(tee);
        //taking the cost that was on that row away from the total cost
        gTotalCost = gTotalCost - subtractCost;

    }
    else 
    {

    }


    }

    // adding the new products to the table and total cost
    addProduct(bPTextFinal, bPValue);
    renderProducts();
    blueprintInfoAdd();
    totalCostFunc();
}
HTML


在你的脚本中有一个else语句,但代码中没有if-缺失部分?是的,对不起,不,当我把它放在这里时,我意外地删除了if部分,所以这不是问题,但我现在已经修复了它,所以如果有人想看到修复,请让我知道我们当然会,否则我们怎么知道,发生了什么事?我的意思是我已经解决了我请求帮助的问题,if-else语句与此无关
<form class="pure-form pure-form-stacked">


    <div class="pure-g">
        <div class="pure-u-1 pure-u-md-1-3">
            <label for="Blueprints"></label>
            <select onclick="blueprintInfoAdd()" id="Blueprints" class="pure-input-1-2"></select>
        </div>
    </div>
</form>
<form id="BPselectorForm" method="post" class="pure-form pure-form-aligned">
    <div class="pure-u-1 pure-u-md-1-3">
        <fieldset id="BPselectorFieldset">
            <div id="BPselectorDiv" class="pure-control-group">
                <input value="0" id="BPselector" onchange="bluePRTfunc(this)" type="number" min="0"> Amount</input>
            </div>
        </fieldset>
    </div>
</form>