PDA

View Full Version : For all the pros here: What is the javascript for copying information?



anaid54
Aug 16th, 2010, 09:38 AM
Hi guys! i would like to ask for your assistance.. i am creating two template for my work.. and i would like to know what is the javascript that in one click i can copy and paste all the details from template #1 to template #2. considering that each field in template 1 will fall into the correct field in template #2..

http://img130.imageshack.us/i/25157983.jpg/

hope to hear from you soon. thanks! you may also email me at [email protected]

Philip M
Aug 16th, 2010, 10:06 AM
document.formname.template2.fieldname.value = document.formname.template1.fieldname.value;
Repeat for each field.

It is not a good idea to reveal your email address in a public forum unless you want to be bombarded with spam by bots.

All advice is supplied packaged by intellectual weight, and not by volume. Contents may settle slightly in transit.

Old Pedant
Aug 16th, 2010, 07:25 PM
That can't be right, Philip.

document.formname2.fieldname.value = document.formname1.fieldname.value

but how can you have a template *inside* of a form????

anaid54
Aug 16th, 2010, 07:39 PM
thank Philip for the fast reply! :) i'll take your advise about the email.. just one last thing, how should i command my button to copy the fields to another form?

Old Pedant
Aug 16th, 2010, 08:07 PM
Looking at your image, it looks like you have two separate windows open at the same time.

That's doable, especially if one of them opened the other. But it might be easier to just use a pair of <frame>s or <iframe>s on the same page.

In any case, the code for doing it with a pair of windows or frames or iframes is a bit different: You have to refer to the "foreign" window/frame/iframe explicitly.

Philip M
Aug 16th, 2010, 10:01 PM
That can't be right, Philip.

document.formname2.fieldname.value = document.formname1.fieldname.value

but how can you have a template *inside* of a form????

Sorry, I do not understand you. :confused:

What I said was

document.formname.template2.fieldname.value = document.formname.template1.fieldname.value;

That should have read


document.formname.template2fieldname.value = document.formname.template1fieldname.value;

Old Pedant
Aug 16th, 2010, 10:15 PM
Oh, sure! That makes more sense.

But what if there are *TWO* forms and/or two <frame>s or <iframe>s or windows?

In fact, I think it's unlikely that he'd have all those two sets of fields in the *same* form.

Philip M
Aug 16th, 2010, 10:21 PM
Oh dear! I'll spell it out -


document.SecondFormname.template2fieldname.value = document.FirstFormname.template1fieldname.value;

Old Pedant
Aug 16th, 2010, 10:26 PM
Yep...that's what I was trying (inadequately, obviously) to say.

If he didn't know that basics of copy field by field, I suspect he wouldn't know to use different form names.

Of course, we still have the question of whether he is using multiple windows or not. Clearly the image he posted implies that he is. But until/unless he comes back and tells us, we won't know.

anaid54
Aug 17th, 2010, 12:36 AM
Hi guys! first off, im a she. :) anyway the two templates are in a frameset. template1 in frame1(left side) and template2 in frame2. what i would like to do is to have the contents of template1 transferred to the contents of template 2 by a single click of create button. thanks a lot for assisting me.. :D

Old Pedant
Aug 17th, 2010, 12:41 AM
Okay, so next questions:

(1) Are the forms named the same in the two framesets?
(2) Are the fields in those forms named the same?
(3) Do you have any case where there are more than one field (in a single <form>) with the same name? (Clearly, radio buttons all have the same name. And often checkboxes do. Any of those?)

(1) is not important at all, but need to know the two names in any case.
(2) is very important. Would be a real pain if not true.
(3) is not important, either. If you never have multiple fields with same name it's easier, but not that hard to account for them.

Oh...and need to know the names or ids of the two frames (and whether they are names or ids).

anaid54
Aug 17th, 2010, 12:51 AM
(1) Are the forms named the same in the two framesets?
- no.
(2) Are the fields in those forms named the same?
- the field1, field2 and field4 in both frames are the same name.
(3) Do you have any case where there are more than one field (in a single <form>) with the same name? (Clearly, radio buttons all have the same name. And often checkboxes do. Any of those?)
- field 1 and field4 are dropdown menu

--

Old Pedant
Aug 17th, 2010, 12:55 AM
Are you saying you want to copy *ONLY* field1, field2, field4???

If you want to copy the other fields, then we have to know the corresponding names in both forms.

*OR* we *COULD* do it just by position. That is first field goes to first field, second to second, seventeenth to seventeenth.

*********
Dropdown menus are *NOT* "same name used more than once" so they aren't an issue.

You know, all this would be a heluva lot easier if you would show the HTML for the actual <frame>s. Preferably, by posting a link to them, rather than posting tons of code in here. But if you must post code here, do so.

anaid54
Aug 17th, 2010, 01:27 AM
ok.. i pm you..

anaid54
Aug 17th, 2010, 01:27 AM
i pm you..

anaid54
Aug 17th, 2010, 02:32 AM
template1:
http://www.filefactory.com/file/b2ge93g/n/template1.html
template2:
http://www.filefactory.com/file/b2ge93f/n/template2.html

these are the links.. i would like to copy-paste all the fields from template1 to template2 that has the same name. (ex. dsl number, cbr number, customer name). and the fields that are not the same will be copied to the textarea field in template2. and the create button in template2 will copy-paste everything.http://img514.imageshack.us/i/40539027.jpg/

anaid54
Aug 17th, 2010, 02:33 AM
template1:
http://www.filefactory.com/file/b2ge...template1.html
template2:
http://www.filefactory.com/file/b2ge...template2.html

these are the links.. i would like to copy-paste all the fields from template1 to template2 that has the same name. (ex. dsl number, cbr number, customer name). and the fields that are not the same will be copied to the textarea field in template2. and the create button in template2 will copy-paste everything.

http://img514.imageshack.us/i/40539027.jpg/