Imam Imam - 3 months ago 18
Javascript Question

Javascript change value when choose on select box

<center>
<div class="main">
<div class="harga">Rp.2,680,000 / Bln</div>
<div class="other">Kontrak Setahun
atau <label>Rp. 2,930,000 / Bln</label></div>
</br>
<div class="traffic">Pilih traffic Anda dibawah ini</div>
<select class="visitor">
<option value="5,000">Up To 5,000</option>
<option value="7,900">Up To 7,900</option>
<option value="17,600">Up To 17,600</option>
<option value="25,000">Up To 25,000</option>
</select>
</br>
Visitor / Bulan
</div>
</center>

<script type="text/javascript">
$(function() {
if((".visitor").val() == "5,000") {
$(".harga").value == "4000";
}
});
</script>


i have this script, how can I change the value on harga from visitor, when I choose selection from select box?

thank you before.

Answer

Use change event like this

$('.visitor').change(function(){
        if($(this).val()  == '5,000'){
                // write your to do action here
        }
});