Bill'o
Bill'o

Reputation: 1

jQuery ie input text issue

I have the following weird issue with the "loading gif" that I want to display in my search bar when the user hits enter. The code works on mozilla and ie 7 on the localhost but only on mozilla on my cpanel... Do you have any clue?? Sorry if this looks obvious :) here is the code, the path is dynamic but of course correct:

$('#searchField').focus(function(){
        $(this).keypress(function(event) {
            if ( event.which == 13 ) {
                $(this).css('background-image', 'url("/dvt/public/images/ajaxLoader.gif")');
            }
        });
    });

thanks a lot

Upvotes: 0

Views: 126

Answers (2)

JAAulde
JAAulde

Reputation: 19560

As far as your image, it seems to me that the URL to the image would be /images/ajaxLoader.gif as /dvt/public seems like a doc root path. With the image on your server, what URL do you put in the browser view it? Also, you can pull the double quotes out of the url() in the CSS.

For the event and keycode, change the name of your event parameter (try e for starters) to avoid collision with the global namespace, then use e.which, per the jQueryfn.keypress docs.

Upvotes: 1

GregM
GregM

Reputation: 2654

Put this to get your event :

if (!event)
    var event = window.event;
var code = event.which || event.keyCode;

It's different in IE and firefox

Upvotes: 1

Related Questions