Welcome, Guest
  • Author Topic: auto highlight text in text input  (Read 2393 times)

    Brandon Rohde

    • Server what's that
    • *
    • Posts: 10
      • View Profile
    auto highlight text in text input
    « on: 07/10/06, 12:40 »
    I am pre-populating a text input component with some text when my app loads. The focus is set to this box as well. Is it possible to have all of the text highlighted when the app loads, so when the user starts typing the current text in the box is overwritten?

    Thanks,
    Brandon

    Jorge Solis

    • Global Moderator
    • Systems Administrator
    • *****
    • Posts: 14616
      • View Profile
    Re: auto highlight text in text input
    « Reply #1 on: 07/11/06, 01:27 »
    To select something, you can use (having an input textfield named myInput)

       Selection.setFocus("myInput")
       Selection.setSelection(0, 10)

    This will not replace whatever you have, instead use (will work just once)

    myInput.onSetFocus = function(){
       this.text = ""
       delete this.onSetFocus
    }

    Jorge


    Brandon Rohde

    • Server what's that
    • *
    • Posts: 10
      • View Profile
    Re: auto highlight text in text input
    « Reply #2 on: 07/11/06, 10:49 »
    Thanks Jorge!

    I got that working perfect on a regular input text field, but is it possible to do the same with a text input component? This is what I currently have... it sets the focus and everything with no problems, however it doesnt set the selection so the user can instantly overwrite the instructions that are in the box.


    searchBox_ti.text = "Search by first name, last name, or email";
    focusManager.setFocus(searchBox_ti);
    Selection.setSelection(0,searchBox_ti.text.length);


    Thanks again,
    Brandon

    Jorge Solis

    • Global Moderator
    • Systems Administrator
    • *****
    • Posts: 14616
      • View Profile
    Re: auto highlight text in text input
    « Reply #3 on: 07/12/06, 01:34 »
    Not selection available, about focus, try:

    listenerObject = new Object();
    listenerObject.focusIn = function(evt){
      evt.target.text = ""
      this.focusIn = null
    }
    myTextInput.addEventListener("focusIn", listenerObject)

    Jorge