CodingConcatenate some stuff

 

Press Ctrl+Enter to quickly submit your post
Quick Reply  
 
 
  
 From:  ANT_THOMAS  
 To:  ALL
39256.1 

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?

0/0
 Reply   Quote More 

 From:  af (CAER)  
 To:  ANT_THOMAS     
39256.2 In reply to 39256.1 
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.
0/0
 Reply   Quote More 

 From:  ANT_THOMAS  
 To:  af (CAER)     
39256.3 In reply to 39256.2 

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

 

Oh, and some nothing at all.

0/0
 Reply   Quote More 

 From:  af (CAER)  
 To:  ANT_THOMAS     
39256.4 In reply to 39256.3 
code:
result = box1.value + ";" +
    [box2.value, box3.value, box4.value].join(":");
0/0
 Reply   Quote More 

 From:  ANT_THOMAS  
 To:  ALL
39256.5 
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))
0/0
 Reply   Quote More 

 From:  af (CAER)  
 To:  ANT_THOMAS     
39256.6 In reply to 39256.5 
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.
0/0
 Reply   Quote More 

 From:  ANT_THOMAS  
 To:  ALL
39256.7 
Seems I was over complicating things. Whilst the code isn't pretty I didn't need to concatenate at all.
0/0
 Reply   Quote More 

 From:  af (CAER)  
 To:  ANT_THOMAS     
39256.8 In reply to 39256.7 
Glad I could help :C
0/0
 Reply   Quote More 

 From:  ANT_THOMAS  
 To:  af (CAER)     
39256.9 In reply to 39256.8 

I'm sorry. I meant to say thanks.

 

I'm so rude :-(

0/0
 Reply   Quote More 

 From:  af (CAER)  
 To:  ANT_THOMAS     
39256.10 In reply to 39256.9 
(hug)
0/0
 Reply   Quote More 

Reply to All    
 

1–10

Rate my interest:

Adjust text size : Smaller 10 Larger

Beehive Forum 1.5.2 |  FAQ |  Docs |  Support |  Donate! ©2002 - 2024 Project Beehive Forum

Forum Stats