Skip to content

Instantly share code, notes, and snippets.

@lucianobragaweb
Created October 24, 2017 18:02
Show Gist options
  • Save lucianobragaweb/9c320c4e6dedb13b5a4fae8a41f0463e to your computer and use it in GitHub Desktop.
Save lucianobragaweb/9c320c4e6dedb13b5a4fae8a41f0463e to your computer and use it in GitHub Desktop.
<form action="">
<select class="target">
<option value="option1" selected="selected">Option 1</option>
<option value="option2">Option 2</option>
</select>
<input type="text" id="txt" name="" value="">
</form>
<script type="text/javascript">
$( ".target" ).change(function() {
var str = "";
$( "select option:selected" ).each(function() {
str += $( this ).text() + " ";
});
$( "#txt" ).val( str );
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment