views:

33

answers:

3

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?

+1  A: 

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"&gt;&lt;/script&gt;
</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>
Brandon Boone
A: 

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.

Matt Williamson
A: 

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());
    });​
samandmoore