Вывести значение value в поле input

<input id="tes">
<select name="test1">
<optgroup label="text">
<option value="50">text0</option>
<option value="10">text1</option>
</optgroup>
</select>
<script>
$('select[name="test1"]').on('change', function(e) {
$('input[id="tes"]').text($(this).val());
});
</script>

Вроде бы работает но и нетскриншот как все не работает


Ответы (1 шт):

Автор решения: Evgenii Evstafev

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.7.1/jquery.min.js"></script>
<input id="tes">
<select name="test1">
  <optgroup label="text">
    <option value="50">text0</option>
    <option value="10">text1</option>
  </optgroup>
</select>
<script>
  $('select[name="test1"]').on('change', function () {
    $('#tes').val($(this).val());
  });
</script>

→ Ссылка