0

am using jquery to bind an event to a text input. The event simply performs an ajax call.

Problem is my code works fine in Firefox, but the event is never triggered in IE6. Heres my code:

    </script type="text/javascript" src="/js/jquery/jquery.js"></script>
<script type="text/javascript">

        // Turn off caching for Ajax
        $.ajaxSetup({

                cache: false

        });

        var ajaxCallURL = "http://<?php echo $_SERVER['HTTP_HOST']; ?>/check";

$(document).ready(function() {

        $("#test").change(function() {

                alert("Event fired");

                $('#result').load(ajaxCallURL,null, function(responseText) {

                        alert("Ajax call successful");

                });

        });
});


</script>
<input style="WIDTH: 30em" id="test" name="test" value="" type="text"/>
<div id="result"></div>

After typing in the text box, both alerts are shown in Firefox, but nothing in IE6.

I also should say that the element is being created using Zend_Dojo classes, but i cant see an issue with using Dojo and jQuery as its works fine in Firefox.

Am thinking it must be that the event is never bound to the element in IE due to maybe Dojo is not fully loaded in IE when $(document).ready is called....

Any ideas anyone??

Many thanks

Stee
  • 1

1 Answers1

1

The change event isn't fired here in some browsers until you click outside and cause a blur to happen.

If you want to fire on every keypress, I would use .keyup() instead of .change(). But this may fire too often to run an AJAX call all the time, so you may want to add a timer in there. See this answer for an example of how to do that.

Community
  • 1
  • 1
Nick Craver
  • 623,446
  • 136
  • 1,297
  • 1,155
  • Thanks for the reply. I came across that trawling the web and have tested my code by inputting in the text box and then clicking on another textbox on the page and still no event. I've also tried the .click to see if this issue was solely relatd to change but its the same problem with .click – Stee Aug 14 '10 at 13:11
  • @Stee - Are you getting any other JavaScript errors in IE6? It sounds like it's not getting executed at all. – Nick Craver Aug 14 '10 at 13:17
  • na no other errors - have run this in Firefox with Firebug and alls ok.. Looks like its the way IE executes dojo....as i just used the dojo.addonload() function and included the jQuery code above in it and it works now in IE... So looks like IE and Firefox load Dojo in different ways as in IE i dont think Dojo is fully loaded when the jQuery $(doc).ready function is called whereas in Firefox it is... – Stee Aug 14 '10 at 13:26
  • @Stee - Which version of jQuery are you using? There have been tweaks to the `document.ready` algorithm over the years. – Nick Craver Aug 15 '10 at 10:46