How do I use javascript (jquery) to set the value of a text box? | XM Community
Skip to main content
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";
@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.
@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