Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Having a placeholder in a Select option [duplicate]

How would I get an equivalent placeholder in a select option? For example when you have a select list it may say in the field "City" then when clicking that it would show all cities in the options.


2 Answers

I think this is what you want .

HTML:

<select id="choice">
  <option value="0" selected="selected">Choose...</option>
  <option value="1">Something</option>
  <option value="2">Something else</option>
  <option value="3">Another choice</option>
</select>

CSS :

#choice option { color: black; }
.empty { color: gray; }

JavaScript:

$("#choice").change(function () {
  if($(this).val() == "0") $(this).addClass("empty");
  else $(this).removeClass("empty")
});

$("#choice").change();

try this jsfiddle.

Don't know if this is what you are looking for

<select>
    <option value="" disabled selected>Select your option</option>
    <option value="value1">Value 1</option>
    <option value="value2">Value 2</option>
    <option value="value3">Value 3</option>
</select>
like image 23
user3811714 Avatar answered Oct 31 '25 07:10

user3811714



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!