3
<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.

5
  • 2
    Add a .change() handler to the select, and put your if inside the handler? Commented Aug 22, 2016 at 3:03
  • Not directly helpful to your question, but consider losing the <center> tag in favor of CSS positioning on div.main. Also, try <br /> rather than </br>. Commented Aug 22, 2016 at 3:06
  • can you write again the script, please Commented Aug 22, 2016 at 3:08
  • i'm sorry wrong question. Commented Aug 22, 2016 at 3:09
  • Also, are you meaning to update the text of div.harga? Because attempting to manipulate the .value property is not gonna work, because value isn't a property of the jQuery object you return in your script. You could use .text(), or else .harga needs to belong to an form element of some sort. And if you meant to have that be an input element, then you need to either use jQuery's .val() method to set it, or get that specific DOM node from the jQuery object, which then has a value property. Commented Aug 22, 2016 at 3:11

1 Answer 1

1

Use change event like this

$('.visitor').change(function(){
        if($(this).val()  == '5,000'){
                // write your to do action here
        }
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.