Rodrigo Souza
Rodrigo Souza

Reputation: 7332

.change() would not work in IE for <select> tags

I have such a combo box in my site and I want it to load some content as soon as it's changed by the user. It's a simple one having each State of my country, check it out: http://jsfiddle.net/tzvyX/

It happens that in IE, the .change() method doesn't work and I don't know what to do to fix it. maybe some other event listener?

Upvotes: 0

Views: 152

Answers (3)

samandmoore
samandmoore

Reputation: 1231

hmmm I have had issues with change in IE but only with radio buttons and onchange. Here is some code I am using that works in IE.

$('#NaviDDL').change(function() {
    var id = $('#NaviDDL option:selected').val();
    if (id == 'default') return true;
    location.href=id;
});

I think the trick is avoiding the use of $(this) in IE for this instance. Try the following:

$('#sctEstado').live('change', function() {
        $('.small-loading').show();
        $('.conteudo').load('onde_encontrar.representante.php?id='+$("#sctEstado option:selected").val());
    });​

Upvotes: 0

Brandon J. Boone
Brandon J. Boone

Reputation: 16472

EDIT: This also came from the same src:

BMan: To get change() to work in IE, the workaround is: $(element).change(function() { doChange(); }).attr("onchange", function() { doChange(); }); Remember that the doChange() function should not be using $(this).

Hard to tell what's going wrong without some sample code, but here is an example from jquery's website that works in IE. src: http://api.jquery.com/change/

<html>
<head>
  <style>

  div { color:red; }
  </style>
  <script src="http://code.jquery.com/jquery-latest.min.js"></script>
</head>
<body>
    <select name="sweets" multiple="multiple">
    <option>Chocolate</option>
    <option selected="selected">Candy</option>

    <option>Taffy</option>
    <option selected="selected">Caramel</option>
    <option>Fudge</option>
    <option>Cookie</option>

  </select>
  <div></div>
<script>
    $("select").change(function () {
          var str = "";
          $("select option:selected").each(function () {
                str += $(this).text() + " ";
              });
          $("div").text(str);
        })
        .change();
</script>

</body>
</html>

Upvotes: 1

Matt Williamson
Matt Williamson

Reputation: 40193

Yes, this is a known problem. You have to watch for the click event and check manually if the value is different from the previous value.

Upvotes: 0

Related Questions