Welcome to the LimeSurvey Community Forum

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

Can I fill a field with responses from other fields?

  • caitifty
  • caitifty's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
9 years 4 months ago #122172 by caitifty
I have a survey where the user enters a 'code' made up of their first and last initial plus the first two letters of their mother's first name plus the day of the month on which they were born, eg My name is Peter D, my mother's first name is Hazel, and I was born on October 20, so my code would be PDHA20 (the idea is to have something relatively anonymous and relatively unique but easy for people to reproduce in 6 months time). It's been suggested that to make things easy I add optional questions for firstname, lastname, mother's firstname, and date of birth, then if the user chooses to answer these questions the 'code' field gets autopopulated with the correct code (otherwise they just work the code out themselves and enter that).

Can this be done with expression manager or does it require javascript? Either way, any pointers would be much appreciated.

Pete
The topic has been locked.
More
9 years 4 months ago #122174 by first
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
9 years 4 months ago - 9 years 4 months ago #122197 by tpartner
Given, for example, the following questions codes...

- fName (First Name)
- lName (Last Name)
- mfName (Mother's First Name)
- dob (Date of Birth)

...you could use an expression like this in the "Default answer" setting for the "code" question:

Code:
{if(!is_empty(fName) AND !is_empty(lName) AND !is_empty(mfName) AND !is_empty(dob), strtoupper(substr(fName, 0, 1)+substr(lName, 0, 1)+substr(mfName, 0, 2)+substr(dob, 5, 2)), '')}

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last edit: 9 years 4 months ago by tpartner.
The topic has been locked.
Moderators: tpartnerholch

Lime-years ahead

Online-surveys for every purse and purpose