I have a dynamic table to calculate price and I want a dropdown list to toggle between hours and rate and price and quantity.
My code works as expected the issue is when I add a row to the table all columns are displayed for a spilt second before the one that should be hidden, gets hidden. I want whatever the user selected to just display when adding a new row.
Javascript
<script>
$(window).ready(function () {
type();
});
function type() {
var type = $("#typeSelect option:selected").val();
if (type === "Hours") {
$('.quantitySelect').hide();
$('.hoursSelect').show();
} else {
$('.quantitySelect').show();
$('.hoursSelect').hide();
}
}
</script>
HTML
<select class="form-control ml-4" style="width:auto;float:left" id="typeSelect" asp-for="OrderItemType">
<option value="Hours">Hours</option>
<option value="Quantity">Quantity</option>
</select>
<table class="table-bordered add_new_field">
<thead>
<tr>
<th>Item Name</th>
<th class="hoursSelect">Hours</th>
<th class="hoursSelect">Rate</th>
<th class="quantitySelect">Price</th>
<th class="quantitySelect">Quantity</th>
<th class="discountSelect colm" data-col="column1">Discount</th>
<th class="taxSelectt">Tax</th>
<th style="text-align:right; padding-right: 10px">Amount</th>
</tr>
</thead>
......