Make bootstrap-select dropdown required

Antonio picture Antonio · Dec 26, 2018 · Viewed 9k times · Source

I have dropdown list in my form which used bootstrap-select to show the dropdown. I want to make if user submit the form it will check the dropdown is have value or not. I already added required inside the <select> tag but nothing happen if I leave it empty and press submit button.

This is my code :

<div class="form-group">
    <label for="location">Location</label>
    <select name="location" id="location-form" required>
       <option value="">Choose Location</option>
       <?php foreach($location as $row) : ?>
       <option value="<?=$row['location_id']?>"><?=$row['location_name']?></option>
       <?php endforeach; ?>
    </select>
</div>

How to make my select dropdown required and can validate it must filled in if user press submit button ? Thanks before.

Answer

bronkula picture bronkula · Dec 26, 2018

A select always has a value set into it. Try using a radio group instead.

Check here for more information on a radio group. HTML5: How to use the "required" attribute with a "radio" input field