View Full Version : paste to multiple fields

05-15-2007, 07:24 PM

I was wondering if javascript can do this or if theres other code (PHP) that can do this. What I wanted to do is paste a string lets say "01 02 03" into 3 fields and it would populate the first field with 01 and the second one with 02 and so on. I didn't know if this could be done or not. any advice would be much appreciated. Thanks in advance

05-15-2007, 08:41 PM
How you do that depends on where the string originally comes from and where you're putting it.
If you've already got it on the server before the user ever sees anything, use PHP and just set the form field values as desired.
If you're getting it on the client, use javascript, and split on the space, then use formname.elementname.value to set it.

05-15-2007, 09:12 PM
Look at the Paste Splitter in my sig.

05-17-2007, 06:23 PM
so with your code...would I be able to split it with spaces??

05-17-2007, 06:34 PM
so with your code...would I be able to split it with spaces??
Yes. Please remove the window.status statements in the code. I only used them for debugging purposes and forgot to remove it.

05-17-2007, 07:08 PM
how can I just set it so that it only separates on the spaces? Also lets say I have 5 values "1 2 3 4 5" what if one of those values are spaces will it know to put the values in the correct fields? or does the values have to be in a certain format to be put in the correct fields? I am guessing that depending on the max length it will fill the fields up to that length even though values might not be that length???

05-17-2007, 08:49 PM
You can have the following:

1 2 3 4 5 (should only be one space in between)
1-2-3-4-5 (can use any delimiter such as / * . or any non-numeric character)