Concatenate some stuff

From: ANT_THOMAS20 Jan 2012 12:32
To: ALL1 of 10

Sounds simple enough but I can't find any reasonable examples. I'm probably not looking hard enough.

 

I want a series of input boxes in a form. Stick some info in each and then to either click a button or the output be generated live (AJAX?) with the result being the input concatenated with certain characters between the input text.

 

So

 

Box 1 : texta
Box 2 : textb
Box 3 : textc
Box 4 : textd

 

Output : texta;textb:textc:textd

 

(the semicolon was intentional)

 

Any ideas?

From: af (CAER)20 Jan 2012 12:56
To: ANT_THOMAS 2 of 10
code:
result = [box1.value, box2.value, box3.value].join(";");


The parameter of the join method is not limited to being a single character - you can use any string you want (e.g. " and "). If you don't specify a string, it defaults to a comma.
EDITED: 20 Jan 2012 12:58 by CAER
From: ANT_THOMAS20 Jan 2012 12:59
To: af (CAER) 3 of 10

It needs to be a variety of things. Well, one ; and the rest :

 

Oh, and some nothing at all.

EDITED: 20 Jan 2012 12:59 by ANT_THOMAS
From: af (CAER)20 Jan 2012 13:00
To: ANT_THOMAS 4 of 10
code:
result = box1.value + ";" +
    [box2.value, box3.value, box4.value].join(":");
EDITED: 20 Jan 2012 13:00 by CAER
From: ANT_THOMAS20 Jan 2012 13:00
To: ALL5 of 10
In the case of the Excel spreadsheet it looks like...

code:
=(CONCATENATE(A11,";",B11,":",C11,":",D11,E11,F11,G11,":",H11,":",I11,":",J11,K11,":",L11,":",M11,":",N11,":",O11,":",P11,":",Q11,":",R11))
From: af (CAER)20 Jan 2012 13:02
To: ANT_THOMAS 6 of 10
Well in that case just use something like
code:
result = [
    box1.value, ";",
    box2.value, ":",
    box3.value, ":",
    box4.value,
    box5.value,
    // etc.
    box23.value
].join("");
You could probably imagine ways to make it more efficient/cleaner, e.g. join all the colon-separated bits first, then add them to the other ones.
EDITED: 20 Jan 2012 13:04 by CAER
From: ANT_THOMAS20 Jan 2012 15:21
To: ALL7 of 10
Seems I was over complicating things. Whilst the code isn't pretty I didn't need to concatenate at all.
From: af (CAER)20 Jan 2012 16:33
To: ANT_THOMAS 8 of 10
Glad I could help :C
From: ANT_THOMAS20 Jan 2012 16:39
To: af (CAER) 9 of 10

I'm sorry. I meant to say thanks.

 

I'm so rude :-(

From: af (CAER)20 Jan 2012 16:41
To: ANT_THOMAS 10 of 10
(hug)