Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem using focus and anchors in IE

Status
Not open for further replies.

raeanita

Programmer
Sep 25, 2002
2
GB
Hi

I am using the following function which is called by onLoad in the BODY tag (e.g <BODY onLoad=FieldFocus('email');>):

function FieldFocus(fieldstr) {
document.forms[1].elements[fieldstr].focus();
if(document.forms[1].elements[fieldstr].type != &quot;select-one&quot;) {
document.forms[1].elements[fieldstr].select();
}
}

I have links that contain the variable to pass as the parameter to this function in the query string (e.g. &quot;field=email&quot;), and also an anchor reference (e.g. &quot;#editemail&quot;).

In Netscape (4.7), all works well i.e. when a link is clicked, the page scrolls itself to the anchor and the focus is set on the given form element and any text present in that field is selected. However, in IE (6), the page scrolls itself to the anchor, any text present is selected, but the focus is not set. The problem appears to be the presence of the anchor, as having tested without the anchors, the focus works ok.

Any ideas/suggestions?

Thanks
:)
 
I have no IE6 to test the case, but anyway I'd leave only focus() action.
It seems useless to perform both actions - first go to anchor, and then focus the field. The latter is sufficient.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top