Imam Ahmad Ashari
Imam Ahmad Ashari

Reputation: 45

Move autofocus after selecting the select option

Want to ask, how do you move the cursor automatically after selecting the form select option?

<select name="id" class="form-control">
  <option>1</option>
  <option>2</option>
  <option>3</option>
</select>
<input type="text" name="name" class="form-control">

I want after I select select the cursor will automatically go to the text name input form

Upvotes: 2

Views: 992

Answers (1)

T&#226;n
T&#226;n

Reputation: 1

Maybe you're looking for something like this:

var select = document.querySelector('select');
var input = document.querySelector('input');

select.addEventListener('change', function () {
  input.focus();
});
<select name="id" class="form-control">
  <option>1</option>
  <option>2</option>
  <option>3</option>
</select>
<input type="text" name="name" class="form-control">

Upvotes: 3

Related Questions