Web Analytics Made Easy -
StatCounter how to highlight text in a textbox onclick link - CodingForum

Announcement

Collapse
No announcement yet.

how to highlight text in a textbox onclick link

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • how to highlight text in a textbox onclick link

    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)?

  • #2
    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.
    Code:
    <input type="text" name="number" value="999" onfocus="this.select()">
    ||||If you are getting paid to do a job, don't ask for help on it!||||

    Comment


    • #3
      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.

      All the code given in this post has been tested and is intended to address the question asked.
      Unless stated otherwise it is not just a demonstration.

      Comment


      • #4
        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.
        Last edited by lli2k5; Sep 26, 2006, 03:59 AM.

        Comment


        • #5
          That doesn't work because you need to use a string
          Code:
          onclick="document.formName.inputName.style.color='#CCCCCC'"
          ||||If you are getting paid to do a job, don't ask for help on it!||||

          Comment


          • #6
            Thanks, it was just those single quotes that killed me

            Comment

            Working...
            X