Welcome to the LimeSurvey Community Forum

Ask the community, share ideas, and connect with other LimeSurvey users!

Hidden fields (always hide) and field reference in Javascript

  • stratacorps
  • stratacorps's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
2 years 9 months ago #217801 by stratacorps
LS 3/latest

I have a custom.js script that parses the URL query string to pre-populate hidden fields in the survey. This works fine if the fields are not set in Display:Always hide this question.

When I do that, I guess I don't know how to access the field value to make changes. To access the field in javascript I'm using $('#answer99999X1X1') just fine, but when the Always hide is on, this no longer exists on the form--it gets changed to 'java999999X1X1' and I can't find any documentation on that.

For now I just don't use the Always hide and in my theme's custom.js I just do a $('#group-0').hide(); to hide the group with the hidden fields that store the parameters passed to the survey. Is this the correct/suggested method?

Is there a way to access the field values whether they are hidden or not, in case a change is made I don't have to change the script.

Background: I have a survey that passes information to the form via the queryString. The value is Base64 and converted into separate field values and used to populate fields I don't want the survey taker to see or be able to change, etc. The logic in my custom.js script checks to see if values have been stored in the hidden fields via the #answer99999X1X1 selector so it skips recalculating/parsing the original query string. However if the form submission is attempted and fails, the query string is now gone/removed when the page refreshes so I needed a way to make the original calculations (base64 conversion) from the original query string persistent.

I have probably overly-complicated things. I can't find a function that accesses the field value no matter what its status is (hidden or visible).
The topic has been locked.
  • holch
  • holch's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
2 years 9 months ago #217805 by holch

LS 3/latest

Please always post the full version, because even if your version is "latest" today, tomorrow it might not be.

Anyway, with Javascript you can only access field that are actually there in HTML. But the "always hide" feature eliminates the text field from HTML completely. You can use this hidden field with expressions, but not with Javascript.

If you need Javascript, you will need to hide the question with CSS. You can apply a CSS class ".hidden" (if I remember right) to hide the question via CSS (there is a field where you can apply custom CSS classes to questions in the GUI of each question.

I answer at the LimeSurvey forum in my spare time, I'm not a LimeSurvey GmbH employee.
No support via private message.

The following user(s) said Thank You: stratacorps
The topic has been locked.
  • stratacorps
  • stratacorps's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
2 years 9 months ago #217810 by stratacorps
(3.27.6+210629) Okay thanks. So hiding the hidden field group is the acceptable method. Probably instead of using JS that gets loaded after the page renders, it would be best to do as you say and use a style so that the group isn't displayed at all while the page loads.

When the visitor clicks the survey submit button, the original URL is gone--so the query string is gone. Is there a way to keep the submit from replacing the original URL? Just curious.

Thanks!
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
2 years 9 months ago - 2 years 9 months ago #217818 by tpartner

Is there a way to keep the submit from replacing the original URL?

No.

If you need the URL parameters in later groups, access them with ExpressionScript referring to your hidden questions.

If you don't use the save-and-return feature, you can load the URL parameters into the browser local storage for later use.

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last edit: 2 years 9 months ago by tpartner.
The following user(s) said Thank You: DenisChenu, stratacorps
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose