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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Highlighted Text in Input Field

Status
Not open for further replies.

anderzreevez

Programmer
Jul 20, 2004
7
GB
Hiya,

Does anyone know how I can have a form appear with a input field with a pre-populated, highlighted text value:

Like this:

<input type =\"text\" name =\"searchstring\" size=\"50\" value =\"Use % as wildcard e.g. dis% returns 'Disney'\" javascript:this.form.searchstring.focus();this.form.searchstring.select();></input>

The idea is that the text is highlighted and focused so that users just need to type to delete and replace what's already there.

Anders
 
I've not tried this, but it might work. Have this HTML:

Code:
<input type="text" name="searchstring" size="50" value="Use % as wildcard e.g. dis% returns 'Disney'">

with this JS being called onload:

Code:
document.forms[0].searchstring.focus();
document.forms[0].searchstring.select();

Replacing the 0 with the relevant number (or name) if your form isn't the first one on the page.

Hope this helps,
Dan

 
Great thanks - this worked:

<body onload = "javascript:document.form2.searchstring.focus();document.form2.searchstring.select();">
 
A little off-topic...

Dan - I can remember in the "old days" when cutting 11 bytes from a program was a major accomplishment!

There's always a better way. The fun is trying to find it!
 
*lol* you can get rid of the space before and after the = sign for a cool 2 bytes too!

Jeff
 
tviman,

You should check out this site:


It's a really, really great site - and I'm loving every minute of the DHTML forum. These guys are crazy (in a great way) - shaving 1 byte off each others 103 byte code - and some of the things they do with JS make the mind boggle.

Dan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top