0

How can I combine two string variables into a separate variable?

422 0 3
Posted   5 months ago

Let's say I have a variable named stringA and another named stringB. I would like to combine them into a third variable named stringC, but separate by a comma.

Example:

stringA = Pleasantville

stringB = New York

stringC = stringA, stringB aka Pleasantville, New York

How might I go about this? I can't seem to use the Set Variable option, because the Value box won't let me put more than one variable in it. Short of potentially using custom JS, is there a way to do this in dominKnow?

 

Comments

( 0 )

Answers  ( 3 )

0
avatar Paul Schneider   |    
Posted   5 months ago
  ●   Edited   5 months ago

You can set the 3rd variable to something like this:

variable1 + ', '+ variable2 

Where the variable1 and 2 are the custom variables (pick from the right flyout) and the + is the "concatinator" and the ', ' contains the value you want to be between them.

Specific steps

Action set variable when page loads

Choose new variable and set as string

In the Value field right click and choose "Variable1"

type: 

+,', '+

Right click and choose "variable 2"

Click apply

NOTE: You can have a space before and after the + or not. (won't make a difference)

Comments

( 0 )
0
avatar mk964m   |    
Posted   5 months ago

How? When I try to put that in the value field, I get an error. When I do it with JavaScript, it works in preview, but not when I publish to our LRS it's bizarre. 

Comments

( 1 )
0
5 months ago     Paul Schneider     637   |   8  

That IS bizarre. I did just publish it as an xAPI package and try it in SCORM cloud and it worked fine. You may need to contact the hosting provider for the LRS and see if they are doing something odd to block that code. I would also use the inspect on the JS console in the browser to see if something was blocked. You may also want to publish as a plain web package or "share link" to see if that is any different.

0
avatar mk964m   |    
Posted   5 months ago

Ahh… the difference is I use double quotes (") and not single quotes ('). I didn't realize that would make a difference. Otherwise, I get a "The value is not valid." error. 
 

thanks for the help!

Comments

( 2 )
0
5 months ago     Paul Schneider     637   |   8  

Ah EXCELLENT. Yes the double quotes usually means interpret it and commas and other stuff can cause some weird items. Hurrah!

0
5 months ago     Luke Hickey     243   |   4  

You get the error using double quotes because the value of the input is expected to be a string, that ONE builds from your input. Think of the input like this "TEXTAREA Your Strings /TEXTAREA". The input value is processed through a JavaScript eval() in order to provide developers access to all JS string manipulation functions.