For some rea...">

Check if multiple options are selected.

I have the following choice:

<select name="extra_especialidad[]" multiple="multiple">

For some reason, the name is sent using parentheses, and I cannot change anything or add anything to the element.

I'm trying to check if a selection option is selected, I tried this without success ...

$("input[name=extra_especialidad\\[\\]]").length; //Gives me 0 always
$("input[name=extra_especialidad\\[\\]]").val().length; //gives me error

Any tips?

Thanks in advance.

+4
source share
2 answers

You can try this ( Example ):

$("select[name='extra_especialidad[]'] option:selected").length;
+9
source

Try the “starts with” selector, so you don’t have to worry about parentheses.

$("select[name^='extra_especialidad']").whatever()

^= in this case, the names starting with extra_especialidad

-1
source

Source: https://habr.com/ru/post/1541192/


All Articles