pheromix
pheromix

Reputation: 19307

How to make select elements required?

With input of type text the attribute required is available. It is not the case for select inputs. So how to make them required ?

Upvotes: 0

Views: 466

Answers (4)

Ambarish Patra
Ambarish Patra

Reputation: 21

use it based on html 5. otherwise you can use any plugin

Upvotes: 1

Ajesh VC
Ajesh VC

Reputation: 635

You can make them required by using html5 attribute required just like below.

<select required>
<option value="">select an option</option>
<option value="value1">Value 1</option>
<option value="value2">Value 2</option>
</select>

View Example in jsfiddle http://jsfiddle.net/88rXX/

Upvotes: 3

Mike Ante
Mike Ante

Reputation: 756

FIDDLE

<form>
    <select required>
    <option></option><!--If this is selected require pop up will appear -->
    <option>test</option><!--If this is selected form will be submitted -->
    </select>
    <input type="submit">
</form>

Upvotes: 4

Dark Hippo
Dark Hippo

Reputation: 1265

Set a default value then on form submission check to see if that default value has changed.

If you're using the JQuery validation plug-in, try this Validate select box

You do have to remember though that just because it's validated client side, doesn't mean you shouldn't also check server side.

Upvotes: 1

Related Questions