Jump to content
xisto Community
wutske

Google Chrome Onfocus='this.select()' Problem

Recommended Posts

I'm having a slight problem with Google Chrome.
I have a fairly straight forward form with only a single text field. When this field gains focus, all text should be selected which should work with the following code:

<form method='get' action='/cms/search.php' style='margin-right: 10px; margin-bottom: -10px' name='searchform'>				<input class='tbox search' type='text' name='q' size='20' value='Zoeken' onFocus='this.select()' />				<input type='hidden' name='r' value='0' /><input class='button search' type='hidden' name='s' value='Zoeken' />				<input type='hidden' name='t' value='all' />				<input type='hidden' name='adv' value='0' />			</form>

In Google Chrome however, the field gets selected and then deselected immediatly and it's almost impossible to select the text in that field.

I've searched the web, but didn't find any solution :) . Is there anybody else who had this problem and knows how to fix it ?

Share this post


Link to post
Share on other sites
SolutionGoogle Chrome Onfocus='this.select()' Problem

We can avoid whatever is happening in webkit browsers as soon as the focus event handler is finished by forking our text selection using setTimeout:

$("input[name=myInput]").Focus(function () {

 setTimeout('$("input[name=myInput]").Select()', 10);

});

Good luck.

- Corey

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.