How can i get the text from the dropdown list and insert it into input text using jquery.
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="form-group">
<label class="sr-only control-label" for="id_lines-0-item">
Item 0:
</label>
<select class="form-control" id="id_lines-0-item" name="lines-0-item" title="">
<option value="">---------</option>
<option value="2">Baja</option>
<option value="3">Fish</option>
<option value="4">Tacos</option>
</select>
</div>
<input id="id_lines-0-label" maxlength="255" name="lines-0-label" type="text" />
<div class="form-group">
<label class="sr-only control-label" for="id_lines-1-item">
Item 1:
</label>
<select class="form-control" id="id_lines-1-item" name="lines-1-item" title="">
<option value="">---------</option>
<option value="2">Baja</option>
<option value="3">Fish</option>
<option value="4">Tacos</option>
</select>
</div>
<input id="id_lines-0-label" maxlength="255" name="lines-1-label" type="text" />
<div class="form-group">
<label class="sr-only control-label" for="id_lines-2-item">
Item 2:
</label>
<select class="form-control" id="id_lines-2-item" name="lines-2-item" title="">
<option value="">---------</option>
<option value="2">Baja</option>
<option value="3">Fish</option>
<option value="4">Tacos</option>
</select>
</div>
<input id="id_lines-0-label" maxlength="255" name="lines-2-label" type="text" />
<script>
var label1 = document.getElementById('id_lines-0-item');
var strlabel1 = label1.options[label1.selectedIndex].text;
$('input:text').val(strlabel1);
</script>
I have tried this above code but it is not working and please forgive me if this a stupid question as i am learning jquery.
I have updated my question. I need to get the text from dropdown list with id="id_lines-0-item" and set the value to input text with id="id_lines-0-label" and respectively getting the value from dropdown list with id="id_lines-1-item" and set the value to input text with id="id_lines-1-label" and so on. Can this be done using DRY(Don't repeat yourself)?