New issue
Advanced search Search tips
Note: Color blocks (like or ) mean that a user may not be available. Tooltip shows the reason.
Starred by 24 users

Issue metadata

Status: Duplicate
Merged: issue 32865
Owner: ----
Closed: Feb 2015
Cc:
Components:
EstimatedDays: ----
NextAction: ----
OS: All
Pri: 2
Type: Bug



Sign in to add a comment

javascript .select() method broken

Reported by iceman...@gmail.com, Nov 17 2008

Issue description

Chrome Version       : chromium 0.3.155.0 build 5561
URLs (if applicable) : http://www.java2s.com/Code/JavaScriptDemo/SelectingTextUponFocus.htm
Other browsers tested:
Add OK or FAIL after other browsers where you have tested this issue:
Safari 3:
    Firefox 3:ok
         IE 7:ok

What steps will reproduce the problem?
1. go to the link
2. type some text in 1 of the fields.
3. blur the field, then focus

What is the expected result?
text becomes selected onFocus

What happens instead?
text becomes selected onMouseDown and de-selected onMouseUp

Please provide any additional information below. Attach a screenshot if 
possible.

this happens with both my mouse and touchpad.
this also happens when i create a test html containing <input type="text" 
onFocus="this.select();" /> and run it locally.

i'm running chromium on vista home premium 32-bit on an LG E-500 notebook.
 
Labels: -Area-Misc Area-Compat webkit-specific Has-reduction report-to-webkit
Status: Untriaged
This is a webkit-specific issue. 
Reduced testcase can be found at: (or see attached file)
http://go/reductions/4505/test_quirks.html
test_quirks.html
319 bytes View Download

Comment 2 by jon@chromium.org, Nov 21 2008

Labels: -Area-Compat Area-WebKit
Status: Assigned
Labels: -report-to-webkit reported-to-webkit
Status: Upstream
Upstream bug: https://bugs.webkit.org/show_bug.cgi?id=22691

Comment 4 by karen@chromium.org, Oct 6 2009

Labels: Mstone-X

Comment 5 Deleted

Comment 6 by comp...@gmail.com, Jan 10 2010

I'm having this same exact problem on my website - http://www.upsidedowntext.com/

This is the code:

	converted.addEvent('focus', function(e) {
		this.select();
	});

converted refers to the bottom textarea box and when focused on, the text inside is
supposed to be selected. this works in firefox and ie, but not chrome or safari.

so to re-produce the bug, enter text in the top textarea box. then click on the
bottom textarea box. you'll notice that the text gets selected, and then de-selected.
does anyone know of a quick fix that can be implemented in JavaScript without writing
browser-specific code?

Comment 7 by Deleted ...@, May 21 2010

Using jquery, you can get around the problem by

$("#myselector").mouseup(function(e){
        e.preventDefault();
});

Comment 8 by evan@chromium.org, Aug 6 2010

Status: ExternalDependency
Has this bug eventually been fixed?
Owner: ----

Comment 11 Deleted

Comment 12 by Deleted ...@, Feb 12 2012

Chrome 16 is still having this problem.

Comment 13 by sjous...@gmail.com, Mar 21 2012

Easy workaround: onmouseup="return false"
The workaround sortof works. After clicking on the field, the text stays selected, but you cannot deselect the text with another click in between letters. If you want to deselect and edit the field you have to use the keyboard arrow keys to deselect first.

Comment 15 by Deleted ...@, May 9 2012

The ie works well. Why

Comment 16 by Deleted ...@, May 21 2012

A slightly better workaround might be this focus code:

var self = this;setTimeout(function() {self.select();}, 0);

Comment 17 by Deleted ...@, Sep 19 2012

Thanks thetoolman, great solution!  The mouseUp workaround is just not feasible if you want to retain the ability to move the cursor inside the field with mouse clicks.  Your 0 delay timer works perfectly though!

Comment 18 by chad...@gmail.com, Sep 27 2012

After a flood of complains in our apps, it's chrome fault.
This bug made our company change our recommended browser back to Firefox. 

Comment 19 by Deleted ...@, Feb 6 2013

I'm having the same behavior/problem in Firefox 18.0.1 on Xubuntu 12.10
Project Member

Comment 20 by bugdroid1@chromium.org, Mar 10 2013

Labels: -Area-WebKit Cr-Content
Project Member

Comment 21 by bugdroid1@chromium.org, Apr 6 2013

Labels: -Cr-Content Cr-Blink

Comment 22 by tkent@chromium.org, Feb 12 2015

Labels: -Cr-Blink Cr-Blink-Forms
Mergedinto: 32865
Status: Duplicate

Comment 23 by Deleted ...@, Jun 16 2015

many thanks @#16 thetoolman, it is ok.

Sign in to add a comment