Search code examples
javascriptjqueryhtmlcssonfocus

Make text field as a select box


When we click on a dropdown we dont see cursor, we just see the whole box with value gets selected, can we do same with text field because in text field I see the cursor blinking.

see image if confused. :D enter image description here


Solution

  • Did you mean you want to disable the text input field? (Thats what I can think). Try this:

    <input type="text" disabled="true" />
    

    What are you trying to accomplish?

    Edit: Read only:

    <input type="text" value="Some value" readonly="readonly" />
    

    I think this is what you are looking for. Read only with no focus.

    <input type="text" value="Some value" onfocus="this.blur()" readonly="readonly" />
    

    Edit 3, Solving Tab Index problem:

    Previous field: <input type="text" tabindex=1/>
    Disabled field: <input type="text" value="Some value" onfocus="this.blur()" readonly="readonly" />
    Next Field:     <input type="text" tabindex=2/>