How do I pass $(this)
into a function. In my example below I want to populate the address textbox with the value of the selected drop-down option label but only if the value selected is not empty.
The following doesn't work?
$("#AddressId").change(function () {
$("#Address").val(function(index, val) {
val = $(this).val();
return val === "" ? "" : $('option:selected', this).text();
}, this).trigger("change");
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<select id="AddressId">
<option value="">-- Please select --</option>
<option value="1">xyz street</option>
...
</select>
<input id="Address" name="Address" value="" type="text">