Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML select dropdown list

Tags:

html

I want to have a drop down list using the select, option tag... but when it first appear I want it to have an information, such as "Please select a name" then the user clicks on the drop down list and selects from the available option... I tried to made the "Please select a name" as an option, but then the user will be able to select this... which is not what I want. Do I need to use javascript to have this feature or what do I need to do?

If there'a jquery way to do this, this would be much helpful

like image 889
aherlambang Avatar asked Dec 03 '10 23:12

aherlambang


People also ask

How do I make a drop-down list in HTML?

The <select> element is used to create a drop-down list. The <select> element is most often used in a form, to collect user input. The name attribute is needed to reference the form data after the form is submitted (if you omit the name attribute, no data from the drop-down list will be submitted).

How do I select all options from a drop-down list in HTML?

To select multiple items, the user has to hold down the shift or ctrl key, then select with the mouse.

How do I select a drop-down option?

A dropdown is represented by <select> tag and the options are represented by <option> tag. To select an option with its value we have to use the selectByValue method and pass the value attribute of the option that we want to select as a parameter to that method.


1 Answers

Try this:

<select>      <option value="" disabled="disabled" selected="selected">Please select a name</option>      <option value="1">One</option>      <option value="2">Two</option>  </select>

When the page loads, this option will be selected by default. However, as soon as the drop-down is clicked, the user won't be able to re-select this option.

Hope this helps.

like image 97
Valentin Flachsel Avatar answered Sep 18 '22 18:09

Valentin Flachsel