javaScript code: Retrieving data from a dropdown and displaying it in the inner HTML of a div.
function showcost() {
var days = document.getElementById("Ddays");
var Dudays = days.options[days.selectedIndex].text;
var div = document.getElementById('cost');
div.innerHTML = div.innerHTML + Dudays * 1200;
}
Dropdown code:
calling the function showcost()
when clicked.
<select class="form-control" name="Ddays" id="Ddays" onchange="showcost()">
<?php $max_days = $HospitalPack->treat_duration + $HospitalPack->recovery_duration; ?>
@for($i = $HospitalPack->treat_duration; $i<=$max_days; $i++)
@if($i == $HospitalPack->treat_duration)
<option selected="selected" value="{{$i}}{{'Days'}}" >{{$i}}{{' Days'}}</option>
@else
<option value="{{$i}}{{'Days'}}" >{{$i}}{{' Days'}}</option>
@endif
@endfor
</select>
div code: displaying calculated values after processing data.
<div class="huge" id="cost">{{$HospitalPack->treat_duration * 1200 + $HospitalPack->treat_cost}}</div>
The above code doesn't seem to be working as expected. I'm having trouble finding the mistake.