View Full Version : how to highlight text in a textbox onclick link
lli2k5
09-26-2006, 07:18 AM
I have an input box of type text. It is a simple onclick text in the box and it becomes blank and you can enter stuff in.
<input type="text" name=number value=999 onFocus="this.value=" >
What I'm wondering is if it is possible that when clicked on a link, the text in the textbox becomes highlighted(background blue, text white)?
_Aerospace_Eng_
09-26-2006, 07:38 AM
I don't think you can change the color because thats a user preference. To select the text in the box you can use the select() method.
<input type="text" name="number" value="999" onfocus="this.select()">
Philip M
09-26-2006, 07:55 AM
Here's an example:-
<p align="center"><center><font face="Arial" size="3" color="#FF0000"><em><b>Additional Comments or Remarks</b></em><br><textarea name = "Remarks" cols = "54" rows = "2" wrap="virtual" style = "font-size: '12pt'; font-weight:'700'; color: 'red'; background:'#FFFFFF';" onfocus = "this.style.background = '#99FF99'" onblur = "this.style.background = '#FFFFFF'"></textarea></font></center></p>
Change the parameters to suit.
lli2k5
09-26-2006, 07:56 AM
oh thanks. But, I was expecting the change to be done remotely.
Say we have a link on another part of the page and when clicking that, the style of an input type changes.
So, I was expecting something like onclick="document.formName.inputName.style.color=#CCCCCC" to change the color of text as to work, but it does not.
_Aerospace_Eng_
09-26-2006, 08:04 AM
That doesn't work because you need to use a string
onclick="document.formName.inputName.style.color='#CCCCCC'"
lli2k5
09-26-2006, 08:13 AM
Thanks, it was just those single quotes that killed me
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.