Hi, Using JavaScript, how do I subtract a weight from a drop-down menu from another drop-down menu, to calculate the amount of weight loss? In total there should be 6 drop-down boxes, these are the following: 1: Pounds (Before), 2. Ounces (Before), 3. Fraction (Before), 4. Pounds (After), 5. Ounces (After), & 6. Fraction (After) For example if: Drop-Down Box 1 = 5 Drop-Down Box 2 = 3 Drop-Down Box 3 = ¾ Drop-Down Box 4 = 3 Drop-Down Box 5 = 2 Drop-Down Box 6 = ¼ Answer = 2.1½ have been lost.
well.. might need some code up to actually see what you're doing but.. i'm thinking you want to have this calculated each time a drop down menu is changed or something of the sort.. so if each option's value is the same as it's text we can do something like this.. <select id="lb1"> <option value="5" onchange="calculate(pounds);">5 <option ... ... </select> <select id="lb2"> <option value="5" onchange="calculate(pounds);">5 <option ... ... </select> ... <p> Pounds Lost: <span id="poundoutput"></span> ... </p> Code (markup): and than the javascript function calculate(weighttype) { if (weighttype == pounds) { document.getElementById("poundoutput").text = document.getElementById("lb1").value - document.getElementById("lb2").value } } Code (markup): i haven't tested any of this.. and their most likely is a better way to do it.. just thought i'd throw you a bone anyways.. good luck
I suspect seriously that this is an assignment question, in which case this isn't going to do you much good.