Hay, i want make some calculator that can make total price with auto fill. First i select option to choose the plan, than after choose the plan the basic price will generated automatically, after that i input the discount value, than the total price will auto generated (basic price-discount). How to implement that to my code:
Here my HTML:
<form name="cal" action="">
<table>
<caption>
<h1>
Kalkulator
</h1>
<h3>
Paket Wisata Imam Tour
</h3>
</caption>
<tr>
<td>Nama Paket Tour</td>
<td>:</td>
<td>
<select name="" id="paket" onchange="myFunction(event)">
<option selected disabled>...</option>
<option value="Bali">Paket Tour Bali</option>
<option value="Korea">Paket Tour Korea</option>
<option value="Eropa">Paket Tour Eropa</option>
</select>
</td>
</tr>
<tr>
<td>Harga Paket</td>
<td>:</td>
<td>Rp.<input id="harga" name="harga" type="number" value="0"></td>
</tr>
<tr>
<td>Diskon</td>
<td>:</td>
<td><input id="diskon" name="diskon" type="number">%</td>
</tr>
<tr>
<td>Total Bayar</td>
<td>:</td>
<td><input id="tot" name="tot" type="text" value=""></td>
</tr>
</table>
</form>
My JS:
function myFunction(event) {
console.log(event.target.value)
if (event.target.value === "Bali") {
document.getElementById("harga").value = 700000;
} else if (event.target.value === "Korea") {
document.getElementById("harga").value = 1500000;
} else if (event.target.value === "Eropa") {
document.getElementById("harga").value = 4000000;
}
};