Form with Drop Down; Selection not showing | XM Community
Skip to main content
Solved

Form with Drop Down; Selection not showing

  • June 19, 2020
  • 3 replies
  • 486 views

KWigg
Level 2 ●●
Forum|alt.badge.img+9
  • Level 2 ●●
  • 52 replies

Hey guys, I've been combing through the forums for two days and just can't find a solution to the issue.
I have a form with a drop down option within it. Everything works fine, until the page is left. Whether returning to the page via back button, or even the question appearing in the survey summary, the options selected are gone. Is there a way to keep the selection, once made, and allow for a change if needed?
Below is the code I'm currently using:
image.png

Best answer by rondev

You need to store the selected option in an embedded data and after inserting the drop down element, check the embedded data, if it is not empty then select that option from the drop down and then put the selected option in input text.
OR
After hiding both the input text, check if they are not empty, then get the text and select the option with same text.

3 replies

rondev
Level 6 ●●●●●●
Forum|alt.badge.img+22
  • Level 6 ●●●●●●
  • 1450 replies
  • Answer
  • June 19, 2020

You need to store the selected option in an embedded data and after inserting the drop down element, check the embedded data, if it is not empty then select that option from the drop down and then put the selected option in input text.
OR
After hiding both the input text, check if they are not empty, then get the text and select the option with same text.


KWigg
Level 2 ●●
Forum|alt.badge.img+9
  • Author
  • Level 2 ●●
  • 52 replies
  • June 19, 2020

rondev thank you, that's very helpful. I had attempte to use an embedded field previously, but didn't think to add a check in the drop down code. Do you happen to know which type of commands I'll need to use in javascript to accomplish this?
Thanks again!


rondev
Level 6 ●●●●●●
Forum|alt.badge.img+22
  • Level 6 ●●●●●●
  • 1450 replies
  • June 19, 2020

After jQuery("#"+that+" .InputText:eq(1)").hide(); add below lines:
jQuery("#s1 option").filter(function() {
  return jQuery(this).text() ==jQuery("#"+that+" .InputText:eq(2)").val();
}).prop("selected", true);

jQuery("#s2 option").filter(function() {
  return jQuery(this).text() ==jQuery("#"+that+" .InputText:eq(1)").val();
}).prop("selected", true);