0
<input type="checkbox" name="KingBed" id="KingBed" />
<input type="checkbox" name="queenbed" id="queenbed" />
<input type="checkbox" name="FullBed" id="FullBed" />
<input type="checkbox" name="headboard" id="headboard" />


check = document.getElementById("headboard").checked;
if(check) { maxTotal += 25 /*PRICE*/; minTotal += 17/*PRICE*/; }

I am looking for an if then statement that if bed1 is chosen, then when headboard is chosen, it will issue one set of prices, but if queenbed, and so forth is chosen, it will list another price.

4

1 回答 1

1

我认为你应该采取不同的方向:

<div>
    <h1>Buy a new bed now!</h1>
    <p>
        <label for="size">Size</label><br />
        <select id="size">
            <option value="twin">Twin</option>
            <option value="full">Full</option>
            <option value="queen">Queen</option>
            <option value="king">King</option>
        </select>
    </p>
    <p>
        <label for="headBoard">Head Board</label><br />
        <select id="headBoard">
            <option value="none">None</option>
            <option value="modelA">Model A</option>
            <option value="modelB">Model B</option>
            <option value="modelC">Model C</option>
        </select>
    </p>
    <p>
        <input type="button" onclick="buy()" value="Buy!" />
    </p>
</div>

然后包含以下 JavaScript

var pricing = {
    size: {
        twin: 100,
        full: 200,
        queen: 300,
        king: 400
    },
    headBoard: {
        none: 0,
        modelA: 100,
        modelB: 200,
        modelC: 300
    }
};

function buy() {
    var sizeSelection = document.getElementById("size").value,
        headBoardSelection = document.getElementById("headBoard").value,
        sizePrice = pricing.size[sizeSelection],
        headBoardPrice = pricing.headBoard[headBoardSelection],
        grandTotal = sizePrice + headBoardPrice;
    alert("Grand Total: $" + grandTotal.toFixed(2));
}
于 2013-04-13T02:52:36.210 回答