Check value of dropdown with JavaScript | XM Community
Skip to main content

Check value of dropdown with JavaScript

  • December 28, 2021
  • 1 reply
  • 128 views

I am trying to check on the value of a drilldown selection against a dictionary of values, so that I can stop the user if specific values where selected.
I managed to use the

this.questionclick
event listener successfully, however it does not work on mobile because drilldowns are displayed differently on mobile, and a click is not registered when the user clicks on an actual selection on the drilldown as opposed to it registering a click on non-mobile.
Now, I am trying to set up an
onchange
event instead of
onclick
but I cannot manage to figure out how to do it. Could anyone help?

This is my code that works:
this.questionclick = function(event, element) {

if (event.which != 0) {
return true;
}

if (element.name != 'QR~QID123~2') {
return true;
}

var selection = jQuery("#"+this.questionId+" option:selected").eq(1).html();

if (!selection) {
return true;
}

for (let i = 1; i <= 10; i++) {
if (selection == carreras[i]) {
var found = true;
var label = carreras[i];
};
};
if (found) {
this.hideNextButton();
alert('Recuerda, esta carrera no puede estar en tu postulación actual.');
} else {
this.showNextButton();
};
};

1 reply

Forum|alt.badge.img+22
  • Level 7 ●●●●●●●
  • January 1, 2022

Try to use

oninput