Have an idea?


JavaScript Reference for Pass-In Fields

How do I reference pass-in fields in Javascript in SSI 6? Does anyone know? It's document.mainform[].value for questions on the page and then you can use [%QNAME%] for question. I tried the [%QNAME%] format for pass-in data and it works in the survey but not in the verification.

The [%PASSINNAME%] should execute and be functionally similar to me having hard coded a value in the script.
asked Jan 25, 2018 by Corey1975 Bronze (780 points)

1 Answer

0 votes
Version 6 hasn't been supported for I think a few years now, but in general scripting is done server side and will evaluate before the HTML page is displayed and any JavaScript code would execute.  So if you did like an if statement in JavaScript verification with something like [%VariableName%] and the data had a value of 4 for the variable, the JavaScript code would just have a 4 in it.

So, I think you're right when you say it should be functionally similar to having a hard coded value.  Perhaps you could give some more details about what exactly you are doing and with what code?
answered Jan 26, 2018 by Brian McEwan Gold Sawtooth Software, Inc. (44,770 points)
I have a set of pass-in fields: firstname, lastname, email, phone, etc.

When I write questions and use SSI script to put them in the survey question itself, the scripting format works: [%firstname%] and so on.

FOr custom verification, the documentation says to reference questions from prior pages using SSI script, for example if I have a single select question called Q1, I reference it in the custom verification as [% Q1 %] and use document.mainform["Q2"].value for question on the current page.

I tried a similar format for pass-ins using SSI script but it kills javascript and doesn't run at all...

SPecifically: var oldfirstname = [%firstname%];
If SSI Script for pass-in fields works in question texts but not in custom verification, then a workaround might involve putting the pass-in field somewhere in the question text, then having the custom verification read the value from the question text rather than from SSI Script directly.

Try adding this to your question text:

<input type="hidden" name="firstname" value="[% firstname %]"/>

Now in custom verification, read the value of this hidden input using your document.mainform code.
Unfortunately, that didn't work. What I did do was put the pass-in fields as part of the textarea coding. I've got an event listener looking to see if anyone clicks into the textboxes to change things. If they do, it flips a flag (via a hidden question) that can be evaluated later.