Name a variable with another variable?
October 30, 2015 12:00 AM
Is it possible to name a variable using another variable? I want to use the user input to create the variable name.
For example, on Page 1 the user enters 123 and it is stored in a variable named "ID". Page 2 the user enters their name in a field. I want to store their name in a variable named "123-username".
In essence, the user is creating new variables. Maybe using a Javascript option?
Thank you for time and help!!!
Discussion (5)
It sounds like something you should be able to do with the "add to variable action". In the Lectora User Guide it states "For string-valued variables, this will result in the joining of the target variable's value and the value specified in the Value field. For example, if the target variable's value is Hello and the value specified in the Value field is World, the resulting value of the target variable is HelloWorld."
I don't think you can add anything in the text box like the dash (that's when JS might have to jump in and help or take over) but you should be able to ask two questions and come up with "123name" when complete. Essentially you would use the same variable but the user would continue to compound the visible information with each new entry.
Using the modify variable action you can concatenate two variables into a new one (including adding the hyphen), however the destination variable must already exist in Inspire. I do not think that is what Max is looking to accomplish. If I understand correctly, Max wants to dynamically create and name a variable after two text inputs (with adding a hyphen). If that is the case you would have to use JavaScript but keep in mind that to use that new variable you would also have to use JavaScript.
Can I ask what you are ultimately trying to accomplish? Why do you want the variable named in that manner? Usually, there is a work around. If there is a will there is a way.
Darrel
As Darrel said, are you sure you need a separate variable for each user? Mind that javascript variable names must not start with a number (in case your "ID" is always a number). Hyphens are not allowed in a variables' name either.
And the name is only for adressing the variable itself which is much easier if you're using the same variable for each user. You can't use the name to adress the user with his "username". You can only use the value of a variable.
Tim
Thank you all for the fast feedback! My purpose was to try and create a localized user database of ~20 people on one computer with the purpose of tracking the progress and bookmark throughout the course based on each employees user ID. I thought I could track each user’s progress in the course and return to where they left off based on the user id they enter when they return to the course. The new variables don’t have to start with a number or contain a hyphen. The computer won’t have access to a LMS.
Could you please explain what are you trying to accomplish? I am sure there must be an easier way than this.
Discussions have been disabled for this post