• The `placeholder` attribute does not set default text in `input`. It sets a placeholder. The `value` attribute sets the default value of the control. You need to define what you really want. – Jukka K. Korpela Dec 17 '13 at 20:40
  • 2 Answers2

    9

    Are you looking for the selected attribute?

    <select>
        <option selected="selected">Select Country</option>
        <option>United States</option>
        <option>Mexico</option>
    </select>
    

    See: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/option

    Julio
    • 2,261
    • 4
    • 30
    • 56
    • 2
      You beat me to it by 13 seconds! +1 – Rahul Tripathi Dec 17 '13 at 19:19
    • @Louis Thanks for the answer, but **NO** I'm not looking for that! I just want to have a ´default text´ such as "optional" or "select country" in the text box. As mentioned ´placeholder ´works fine with the ´input´ box but for some reason doesn't work with the ´select´ box. – Stefan Weiss Dec 17 '13 at 19:26
    • 2
      I fear you have fundamentally misunderstood your problem, and as a consequence fail to see the correctness of both @RahulTripathi and my answers. – Julio Dec 17 '13 at 19:28
    • @Louis I was looking for a simple way to add a text inside the text box. It's suppose to be something like **please select** or **optional**. It will disappear once the user starts to type in something. Placeholder is something I found during my research - I never used it before and it worked. But as you can see from my question, I wasn't insisting on that. But I still didn't understand how to solve my problem with the way you showed. How can I implement this? – Stefan Weiss Dec 17 '13 at 23:01
    • @Teo you don't type in a select field, so your question doesn't make sense. Are you thinking of something like this: http://harvesthq.github.io/chosen/ ? – Julio Dec 17 '13 at 23:28
    • @Louise Sorry for the confusion, I mean **select** not type. Additional to this, I finally understood what you mean and you're right, this is the solution for my problem. Somehow I was so focused on the solution with placeholder in combination with the **input** box. That I didn't see the difference of both issues. So thanks for pointing it out! +1 for your efforts! – Stefan Weiss Dec 17 '13 at 23:33
    • 1
      +1 for pointing out the correct approach instead of blatantly stating "It's not possible" and for the reference :) – Amal Murali Dec 19 '13 at 20:53
    4

    I think you can use it like this:

    <select>
        <option selected="selected">Default Option</option>
        <option>1</option>
        <option>2</option>
    </select>
    

    ie, use selected="selected" for the option you want to be the default.

    or you may try this:

    <select>
        <option value="" disabled selected>Default Option</option>
        <option value="1">1</option>
    </select>
    
    Rahul Tripathi
    • 168,305
    • 31
    • 280
    • 331