I am having a modal with a Select Menu
. I am getting the id assistant_id_1
of the select menu but i am trying to get the value assistant_name
to hidden input assistant_name_1
so i can use it in php code $assistant_id_1_name = $_REQUEST["assistant_name_1"];
HTML code:
<div class="form-group row">
<label for="assistant_id_1" class="col-xs-4 col-form-label">Assistant 1:</label>
<div class="col-xs-5 form-group">
<input type="hidden" name="assistant_name_1" id="assistant_name_1">
<select id="assistant_id_1" name="assistant_id_1" class="form-control select2" style="width:100%;">
<option value="">Please Select</option>
</select>
</div>
</div>
JS code:
$(document).ready(function() {
get_assistant('#assistant_id_1');
$('#recall_modal').modal('show');
});
function get_assistant(ele, selected = 0, filter = 'None') {
var action = "assistant";
$.ajax({
type: "GET",
url: 'api/get_data.php',
dataType: 'json',
data: {
action: action,
filter: filter
},
success: function(result) {
if (result.success === true) {
html = '<option value="">Please Select</option>';
$.each(result.assistant, function(key, value) {
html += '<option value="' + value.assistant_id + '"';
if (value.assistant_id == selected) {
html += ' selected';
}
html += '>' + value.assistant_name + '</option>';
});
$(ele).html(html);
}
}
});
}
$('#assistant_id_1').change(function () {
$('#assistant_name_1').val(('#assistant_id_1').find('option:selected').text())
})
I am getting an error Uncaught TypeError: "#assistant_id_1".find is not a function