views:

414

answers:

2

I want to use the defaultfocus property on a form in ASP.Net, and therefore I set this property to a textbox. This works as expected on IE, but in the Safari 4 beta, the content of the textbox is also selected. How can I make this work as expected on Safari?

i tried also some jquery call, and the problem is there also:

$("input:visible:enabled:first").focus();

in safari it looks like it calls select() instead of focus. does anyone have a solution to this problem?

A: 

I believe the .net stuff is hooking into an IE specific defaultfocus property that Safari/Other browsers do not have.

I presume this auto-focuses the particular field?

scunliffe
yes, the focus is on the right field. but in safari the content of the field is also selected.
karlis
ah, I see... hmm, to be honest, this is what I do when auto-focusing a field... plain focus if there is no content, select() if there is (it makes deletion easier)... this is likely hard coded into the way safari works.
scunliffe
+1  A: 

it seems that you have to set the value of a textbox to get the focus in the field instead of the selection:

    var firstInput = $("input:text:first");
    firstInput.focus();
    firstInput.val(firstInput.val());
karlis