JP29
JP29

Reputation: 625

Javascript onchange() not working in chrome and IE

I have a total variable that I update with a refresh get request using on change from a drop down box with PHP/JS. Seems to work fine in Firefox, but not at all with Chrome / IE. Any suggestions?

<form action='cart.php' onchange = 'go()'>
<select id = 'postinfo' name = 'postage'>

<script>
  function go() {
    var x = document.getElementById("postinfo").value;
    if (x == "express") {
        var price = 9.99
        window.location.href = "cart.php?delivery=" + price + "&item=express"; 
    }else if (x == "free"){
        var price = 4.99
        window.location.href = "cart.php?delivery=" + price + "&item=free"; 
    }
  }
</script>

Upvotes: 0

Views: 2826

Answers (2)

Jordizle
Jordizle

Reputation: 252

You should have the 'onchange' JavaScript event attached to your select tag not to your form tag.

for example:

  <form>
    <select onchange="alert('I just changed!!!');">
      <option>1</option>
      <option>2</option>
    </select>
  </form>

HTH

Upvotes: 0

epascarello
epascarello

Reputation: 207501

There is no onchange event on a form element.

You probably want it on the select element.

Upvotes: 5

Related Questions