How do I use javascript (jquery) to set the value of a text box? | XM Community
Solved

How do I use javascript (jquery) to set the value of a text box?

  • 12 July 2018
  • 4 replies
  • 399 views

Here's my problem. I have a survey where I prefill the textbox with embedded data calculated from a previous set of questions. That works wonderfully. But, when the user goes back to do the survey again, the calculations are not being populated because the form is prefilled with their prior answers.

In order to get around this, I'd like to set the textbox value using javascript rather than embedded data. Something like document.getElementByID("Question").value = "ThisValue";

To complicate things, the textbox is actually inside a side by side question. The actual question ID is ${q://QID22/ChoiceTextEntryValue/3/2} and I can't figure out how to do this. Any help is appreciated! I'm certain it's simpler than I know.

For what it's worth, I've tried this to no avail: document.getElementById("QR~QID22#3~2").value = "My value";
icon

Best answer by Akdashboard 12 July 2018, 22:08

View original

4 replies

Userlevel 7
Badge +6
@Alwalser - There might not be a need for javascript. Have you considered using branch logic after the question to make the value you are piping in an embedded data value (instead of a question value), then applying branching logic at the top of the survey that would branch if they took the survey already (any number of ways to do this), and then populating the same embedded data field as blank. This way the field is blank until re-populated later in the survey.
interesting. I have not ever used branch logic but I will try it out! thanks for the lead
Man @Akdashboard, I REALLY overthought that. I just created a new question at the top that said "are you retaking this survey" then added display logic to show the same questions, only copies, if the answer was YES and the udpated values appeared. Thanks for shining a light on that for me.
Userlevel 7
Badge +6
@Alwalser - Glad I could help! I am still learning JavaScript only when needed (although I'd like to learn more), so it usually isn't my go-to solution.

Leave a Reply