0

Following is my code from dropdown. I am trying to make sure that person has to select option from dropdown but not "Please select an option...". I can submit form without giving me error. I want to sent error that please select option if person has not selected any option from dropdown.

<div class="form-group">
    <label name="ContactType">Contact Type:</label>
    <select class="form-control" name="ContactType" pattern".{3,}">
        <option value="Phone">Phone</option>
        <option value="Meeting">Meeting</option>
        <option value="None">None</option>
        <option value="" selected disabled>Please select an option...</option>
    </select>
</div>

New in HTML. What should I do ? I don't mind using jquery or javascript for solution.

Thanks

Kush Patel
  • 3,685
  • 5
  • 42
  • 65
  • Please select an option... get that first – AthMav Oct 21 '16 at 15:45
  • 1
    This is a slightly different question than the "duplicate" question that was linked. He's not asking for the "placeholder" experience, just forcing a selection. – talemyn Oct 21 '16 at 15:48
  • Above code send me no information if i don't select option from dropdown. I want to force person to select option. – Kush Patel Oct 21 '16 at 15:50
  • Anyway, the answer is to add the `required` attribute to your `select` element. As noted on MDN (https://developer.mozilla.org/en-US/docs/Web/HTML/Element/select), `required - A Boolean attribute indicating that an option with a non-empty string value must be selected.` Since your default selection has an empty string as a value, selecting it will not meet the "required" check. – talemyn Oct 21 '16 at 16:00

0 Answers0