dave
dave

Reputation: 210

Gettin the value from a selected option in Selectize.js

I am using multiselect in selectize.js, how do i get the vales from the select options: html:

<div class="selectBox1" multiple="multiple">
        <select id="period">
          <option value="day">Day</option>
          <option value="week">Week</option>
          <option value="month">Month</option>
          <option value="year">Year</option>
        </select>

select.js init:

$(document).ready(function($){
  
  $('#period').selectize({
  sortField: "text",
  placeholder: "Select a Period..",
});
});

I tried to get the value by simply using this code:

var values = $('#period').val();
console.log(values)

but it returns an empty array. what can i do?

Upvotes: -1

Views: 251

Answers (1)

Ahmad Othman
Ahmad Othman

Reputation: 141

Just add onChange handler:

$(document).ready(function($){
  $('#period').selectize({
    sortField: "text",
    placeholder: "Select a Period..",
    onChange(value) {
      console.log(value);
    }
  });
});

Upvotes: 0

Related Questions