Skip to main content
Inspiring
April 5, 2022
Resuelto

HTML5 Canvas - Get selected option label for combobox

  • April 5, 2022
  • 4 respuestas
  • 274 visualizaciones

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...

    Este tema ha sido cerrado para respuestas.
    Mejor respuesta de kglad

    dataA is your jason array of data.

    4 respuestas

    kglad
    Community Expert
    Community Expert
    April 5, 2022

    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;
    }
    }
    }

    Inspiring
    April 6, 2022

    @kglad   Thanks.  What is dataA?  I'm getting not defined...

    Inspiring
    April 6, 2022

    @kglad 

     

    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'];
    		}
    	});