views:

41

answers:

2

I have a search text field and search button, when button is clicked with default text in text field, or null value, an alert pops up and sets focus back on search text field. This works very well on all major browsers but not in safari.

I tried it even with out jquery, but didn't work. When the focus falls on search text field, I have another jQuery function, is that the problem.

The code that sets focus on search text is:

if (defaults.keyword == SEARCH_TIP || defaults.keyword == '') {
    alert(SEARCH_NULL);
    $('#store_search_keyword').focus();
    return false;
}

The code on focus is:

var search_dom = $('#store_search_keyword');
var search_text = search_dom.val();
search_dom.focus(function(){
    if ($(this).val() === SEARCH_TIP) {
        $(this).val('');
    }
});

any help is appreciated, thanks..

+2  A: 

You should call the native DOM focus() method, like this:

document.getElementByID('store_search_keyword').focus();
SLaks
I tried that, didn't work. I have another function upon focus, I'm not sure is that the cause of all these troubles?
pMan
A: 

That doesn't work properly in Safari.

http://whatsthepointy.blogspot.com/2010/05/safari-focus-and-popup-alerts.html

The problem is caused by that "alert()" in your handler. Safari doesn't realize that its main window regains focus after the alert box is cleared, and when Safari doesn't think it's the focused application it pays no attention to .focus() calls on anything.

Pointy