I have a txtSubTotal
text box, a discount
drop down and a txtGrossTotal
text box. txtSubTotal
text box is updating when the ADD
button is clicked. txtGrossTotal
text box is updating when the drop down value is selected. But, when updating the txtSubTotal
text box, at the same time txtGrossTotal
text box should be updated for the default drop down value, which is "0". Here, txtGrossTotal
should be the value of txtSubTotal
.
Below is my code, it doesn't display the txtGrossTotal
when the drop down has it's default value. (But, after selecting another option, and again select the default value, it updates the txtGrossTotal
.)
function discountedGrossTotal(dropdownVal){
var discountOption = document.getElementById("discount"),
subTotal = document.getElementById("txtSubTotal"),
grossTotal = document.getElementById("txtGrossTotal").value;
grossTotal.value = subTotal.value - (subTotal.value * dropdownVal/100);}
discount
drop down
<select class="select" id="discount" name="discount" onchange="discountedGrossTotal(this.value);">
<option selected>0</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
</select>
txtGrossTotal
HTML
<div id="gross_total_div">
<input name="txtGrossTotal" type="text" id="txtGrossTotal" size="15" readonly/>
</div>
discountedGrossTotal
function. It is likely that you have not set it as selection events for the fields – Bonatti