Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

HTML5 Canvas - Get selected option label for combobox

Engaged ,
Apr 05, 2022 Apr 05, 2022

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

237
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Apr 06, 2022 Apr 06, 2022

dataA is your jason array of data.

Translate
Community Expert ,
Apr 05, 2022 Apr 05, 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;
}
}
}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Apr 05, 2022 Apr 05, 2022

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Apr 05, 2022 Apr 05, 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'];
		}
	});

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 06, 2022 Apr 06, 2022
LATEST

dataA is your jason array of data.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines