user3045457
user3045457

Reputation: 164

How to focus on next field after selecting Selectize.js field

How can I focus to next element after I select an item from selectize.js select element ? I did not find onSelect option in selectize.js. Note:my next element is also selectize.js select element

enter image description here

Upvotes: 2

Views: 803

Answers (1)

Swati
Swati

Reputation: 28522

You can use change event on first select-box . Then , whenever first-select box gets change use instance of selectize and call .focus() for second select-box.

Demo Code :

var $select = $('#a').selectize();
var $select2 = $('#b').selectize();
// get instance
var selectize = $select[0].selectize;
var selectize2 = $select2[0].selectize;
//on change of first select or use blur event
selectize.on('change', function onChange() {
  selectize2.focus() //focus second one 
});
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/selectize.js/0.8.5/css/selectize.css" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/selectize.js/0.8.5/js/standalone/selectize.min.js"></script>
<select id="a">
  <option value="1">A</option>
  <option value="3">N</option>
</select>
<select id="b">
  <option value="1">A</option>
  <option value="22">Ar</option>
</select>

Upvotes: 2

Related Questions