L
L
lev892022-04-20 11:31:44
css
lev89, 2022-04-20 11:31:44

How to do validation for select?

By default, select required, if the user has not selected anything from the list, then the form will not work. I need that if the user has not selected anything from the list, then get an error message next to the select that you need to select a value

<select name="" class="form-control" required>
  <option selected disabled value="">--Выбрать--</option>
  <option value="1">value 1</option>
  <option value="2">value 2</option>
  <option value="3">value 3</option>
  <option value="4">value 4</option>
  <option value="5">value 5</option>
</select>

Answer the question

In order to leave comments, you need to log in

2 answer(s)
O
ostup17, 2022-04-20
@ostup17

Отличное решение здесь

T
TheAndrey7, 2022-04-20
@TheAndrey7

А в чём собственно заключается проблема? Мне кажется, атрибуты selected и disabled не совместимы друг с другом. Их вообще стоит убрать оба (по-умолчанию выбирается первый option), браузер должен ругаться на пустой value у option.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question