Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > Safari Javascript and focus()

Safari Javascript and focus()
Thread Tools
sushiism
Grizzled Veteran
Join Date: Jun 2002
Location: UK
Status: Offline
Reply With Quote
Mar 19, 2006, 04:17 PM
 
Alright in Firefox when I use focus() on a textarea the caret moves right to the end of the text, however in safari it stays put.
On further testing it seems Safari doesn't even focus on the textarea at all, anyone got any ideas why this may be?

Thanks in advance
     
sushiism  (op)
Grizzled Veteran
Join Date: Jun 2002
Location: UK
Status: Offline
Reply With Quote
Mar 20, 2006, 06:13 AM
 
ok found out that safari doesn't seem to set the focus if you select the element via setting it to a variable using getElementById, forms[0].elementname however works but the caret still stays in the last position in the text area.
Anyone know how to move it to the end?
     
Chris O'Brien
Grizzled Veteran
Join Date: Nov 2003
Location: Hebburn, UK
Status: Offline
Reply With Quote
Mar 20, 2006, 07:21 AM
 
Yeah, Safari will put the carat back to where it was when the text area lost its focus.

Something like:

Code:
function focusToEnd() { var to_focus = document.getElementById("id_of_textarea"); var to_collapse_to = to_focus.value.length; to_focus.focus(); to_focus.setSelectionRange(to_collapse_to, to_collapse_to); }
should work.

I should also note that calling focus() on the element referenced using getElementById worked fine for me... which version of safari are you using?
Just who are Britain? What do they? Who is them? And why?

Formerly Black Book
     
sushiism  (op)
Grizzled Veteran
Join Date: Jun 2002
Location: UK
Status: Offline
Reply With Quote
Mar 21, 2006, 10:18 AM
 
I'm using safari 2.0.3, cheers I thought something to do with selections might sort it out and I'll double check my getElementById method again to see if it was just a small inconsistency caused by caches
     
   
Thread Tools
 
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Top
Privacy Policy
All times are GMT -4. The time now is 05:20 PM.
All contents of these forums © 1995-2017 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.8 © 2000-2017, Jelsoft Enterprises Ltd.,