Adding text string variables together

May 09, 2012

There was a recent discussion about adding numeric variables together into a single variable output. Does anyone have any ideas how to string the values of several input TextEntry boxes into one final variable?

28 Replies
Steve Flowers

Hey, Kevin - 

You'll need to replace the carriage returns with a break. Take a look at the code in the certificate page here:

http://community.articulate.com/forums/t/12471.aspx

Looks like this (well... if the forum didn't eat my tags):

//this grabs the player object from the parent (launching window)

var player=window.opener.GetPlayer();

//now we pull a field value. You can pull as many as you like. That replace jumble lets you bring over text fields with multiple lines.

var learnerName=player.GetVar("learner").replace(/(\r\n|\r|\n)/g, '<br />');

document.write("<div class='result'>"+learnerName+", you have passed <b>The Grueler</b>!<br/><br/><em>For that feat, you deserve a break. Take 30 seconds. Then get back to work!</em></div>");

The ".replace(/(\r\n|\r|\n)/g, 'break tag' bit is what takes care of breaking up those lines.

Ron Lucindo

Phil Mayor said:

Thanks for the explaination Steve, I fluked a line return.

The more javascript I get to use the more I understand it.

Oh and thanks for the codeacademy link really great site


Hi Guys,

Can you please explain further how to do a concatenation? I have numeric keypad from 1 to 9 and 0. I want to animate when a user successfully click the so called password. Let say they enter 1234, then I will proceed with the show layer to animate. My big question is, how to get the input together? How to concatenate the user's input? How to join two strings together?

Thank you.

Phil Mayor

Not sure you need to concatenate here, if you are not using decimals just multiply by ten and add the number

e.g

First press = 1 (triggers multiply by ten and add 1) visible = 1

second press = 2 (triggers multiply by ten and add 2) visible = 12

third  press =  3 (triggers multiply by ten and add 3) visible = 123

forth  press =  4(triggers multiply by ten and add 4) visible = 1234

Ron Lucindo

Phil Mayor said:

Not sure you need to concatenate here, if you are not using decimals just multiply by ten and add the number

e.g

First press = 1 (triggers multiply by ten and add 1) visible = 1

second press = 2 (triggers multiply by ten and add 2) visible = 12

third  press =  3 (triggers multiply by ten and add 3) visible = 123

forth  press =  4(triggers multiply by ten and add 4) visible = 1234


Hi Phil,

Thanks a lot for your reply. Sorry for my lack of understanding, but I don't seem to get the logic you posted. for example,

on second press = 2 (2 x 20 +2) = should be equal to 22. Following the logic you gave.

And also, aside from 1-9 and zero keys, there are two more, there is a " * " and " c ". C is to clear the input, and * is used in the programming. I am trying to figure out, how I can get the users input, and compare if they have the right password. Let say, the password is 112335. Thanks a lot.

Ron Lucindo

Hi Phil,

Thank you for your reply again. It is greatly appreciated. I completely understand your reply above. But I don't seem to get it on the succeeding line, sorry.

1 -> 1 x 10 =10+2 = 12

2.--> 2x10 = 20+3 = 23

3--> 3 x 10 = 30+4 = 34

4. --> 4x10 = 40. 

Can you please check where I had it wrong? Thank you.

Also, does the algorithm you are suggesting works if the password is: 112335

Thank you phil

Phil Mayor

I think you are still missing what I am trying to say (but it is likely the way I am saying it), you need a variable for this sake lets call it display

Each button 1 -9 has two triggers one multiplies display by 10 the other adds the respective value from 1-9 to the value of display

My example on each button press

1-> display value = 0  x 10 +1 = 1

2-.>display value = 1  x 10+2  = 12

3 ->display value = 12 X10+3 = 123

4 ->display value = 123 x 10 +4 = 1234

Will work for every example

rTrigger order is important must be x10 then  +x where x is the value of the button.

Ashley Terwilliger-Pollard

Hi Michael,

Which .story file are you referring to? This thread dates back a bit - so I wasn't certain which one you were looking at to try and open it to see if I could see the information Also, the javascript element won't be visible on the slide itself, you'll have to look at the triggers .

Hopefully someone else with more Javascript expertise in the community will also weigh in and share any thoughts here as well. 

This discussion is closed. You can start a new discussion or contact Articulate Support.