Copy link to clipboard
Copied
How do I get the selected option label for combobox?
function assignDataF(data) {
for (var i = 0; i < data.length; i++) {
$('#patients_cbx').append($("<option/>").attr("value", data[i]).text(data[i].label));
}
}
//Select patient from ComboBox list
$("#dom_overlay_container").on("change", "#patients_cbx", showPatientDetails.bind(this));
function showPatientDetails(evt) {
root.patientDetailsModal.visibility = true;
root.patientDetailsModal.patient_name.text = evt.target.innerText;
}
Tried with evt.target.innerText but it just gives me all the labels in the combobox...
1 Correct answer
dataA is your jason array of data.
Copy link to clipboard
Copied
use:
function showPatientDetails(evt) {
root.patientDetailsModal.visibility = true;
root.patientDetailsModal.patient_name.text = labelF(Number(evt.target.value));
}
function labelF(value){
for(var i=0;i<dataA.length;i++){
if(dataA[i].data == value+1){
return dataA[i].label;
}
}
}
Copy link to clipboard
Copied
@kglad Thanks. What is dataA? I'm getting not defined...
Copy link to clipboard
Copied
As I needed to get an array of data in JSON anyway for the 'patient', I went another way, using the evt.target.value of the combobox selected option, then doing another Query AJAX call to the database querying the primary key for that record based on the value of the selected option. Works fine:
$("#dom_overlay_container").on("change", "#patients_cbx", showPatientDetails.bind(this));
var patient_pk;
function showPatientDetails(evt) {
root.patientDetailsModal.visible = true;
patient_pk = evt.target.value;
$.ajax({
type: "POST",
url: 'scripts/get_patient_details.php',
dataType: 'json',
data: {
patient_pk: patient_pk
},
success: function (data) {
root.patientDetailsModal.patient_name.text = data['patient_name'];
}
});
Copy link to clipboard
Copied
dataA is your jason array of data.

