Detecting if an item is selected in the list or not via jquery

I have a multi-segment list and before submitting the form I want to check if the user selects a parameter or not via jquery

+3
source share
3 answers

You can use the function .val()to get the selected values. For multi select, it returns an array of selected values ​​or null if no items were selected:

if ($('#idofselect').val() != null) {
    // user has selected at least one value
}
+7
source

This works for you:

$("#formID").submit(function()
{
  var selectValue = $('#selectList').val();
  if(selectValue != null)
  {
      // blah
  }
});
+1
source
$('#list option:selected').length

I will get the number of selected objects. (obviously replace "#list" with your selector).

+1
source

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


All Articles