0

Is it possible to force/require a user to make a selection from a drop down menu?

I am thinking something like the below, but it still takes the first value "Volvo".

By default "Volvo" is selected. What I want is for the browser to know that the user has to make a selection and not to accept the auto default value.

< form action="" > 
< select name="cars" required>
< option value="volvo">Choose a Car Name</option >
< option value="volvo">Volvo</option >
< option value="saab">Saab</option >
< option value="fiat">Fiat</option >
< option value="audi">Audi</option >
< /select >
< /form >

In my case, say the first option value as "Choose a Car Name" followed by 4 car names. "Choose a Car Name" will be displayed right across the drop down field. Even after making it as required field, it will choose the default value as "Choose a Car Name" instead of the real car name values.

The user needs to choose a car name and only then he should be able to submit

Megu
  • 5
  • 4
  • @David - I have updated my qn. Please let me know if this is clear now. – Megu Nov 27 '17 at 18:30
  • 1
    Possible duplicate of [Can I apply the required attribute to – Grzegorz Krauze Nov 27 '17 at 18:32

1 Answers1

0

You absolutely can do that by changing value of option "Choose a care name" to ""

Something may look like this:

 <option value="">Choose a Car Name</option >

because <select required> makes sure the value of <option> is not nil.

PhDang
  • 79
  • 2