Is it possible to copy values from a form on page x to a form on page y using javascript. The data is the same but just different pages and different applications?
-
I have looked into jquery clone() but examples are on a single page. I would like to copy from one application to another application. – mpora Feb 04 '13 at 21:08
-
In what way does the JavaScript from one page "see" the other page? It would need to be able to access it somehow in order to modify it. Is one of them perhaps within an iframe of another or something like that? – David Feb 04 '13 at 21:09
-
1you can use a cookie - but `$_SESSION` on the server side would be the normal way of doing this – AvL Feb 04 '13 at 21:09
-
I don't totally understand the question - are you going from one page to another? Are you doing cross tab bleeding edge? If you're doing data transfer between tabs I would use something like pubnub to "beam" the data live to other computers (as separate tabs are rarely connected at all). – Christian Stewart Feb 04 '13 at 21:11
4 Answers
Yes, you can do this. Using AngularJS you could use "search" variables and then plug these into the form. Using normal javascript you may be able to use a # with the data. Using PHP + normal javascript (more secure) you can send a POST to the page (which is a PHP page) and have the page, if the POST params with your values exist, put a javascript fragment on the page setting the values of the form when the page is done loading.
Cookies are also always an option :)
[EDIT]
After discussion, here is the solution to the question: GitHub

- 15,217
- 20
- 82
- 139
-
This is an excellent lead. I am going to see how I can do it so when the second page opens, the values are already filled in. If it works, I will be the happiest man alive today. – mpora Feb 04 '13 at 21:47
-
How are you going to do this? Which method? I gave you like 4 lol. If you do get it to work please accept. – Christian Stewart Feb 04 '13 at 23:21
-
I think you're using the PHP method - you can do this either by injecting the POST values directly into the HTML (I.E ">) but you'll want to be sure to 'sanitize' the POST variables, check if there's no cross site scripting (no – Christian Stewart Feb 04 '13 at 23:23
-
What I am trying to do is to insert info in a non-user friendly form that was previously designed as the people who made it don't want to change it. So I am mirroring the same form but making it more user friendly. Thus my form would be collecting data to insert in the bad form. – mpora Feb 05 '13 at 15:45
-
I am also looking at Firefox InFormEnter where I would submit data to it and open the other form and just click to autofill as I do not have control over the form. – mpora Feb 05 '13 at 16:17
-
If you want to do this you can use a JavaScript page load to load the existing form into the view after the page has loaded. you can then use jquery to fill the form. – Christian Stewart Feb 05 '13 at 18:52
-
let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/23997/discussion-between-mpora-and-christian-stewart) – mpora Feb 05 '13 at 20:00
-
Hi, Did my answer solve your problem? If so please accept. If not, let me know and I'll help! – Christian Stewart Feb 06 '13 at 05:41
Actually, cross-tab JS is not allowed. I am not sure about bleeding-edge apis.
Theoretically, it is possible to do via local storage with a same-origin restriction. But you'd better don't mind this option.
Also, try to play with cookies.

- 31,729
- 16
- 153
- 201
If it's just from one page to another you can append the data to the request as POST (with PHP) variables, or a simple query string (GET) and read them once the page has loaded/populate relevant fields - if the second page is loaded directly from the first.
If it needs to be retained until an unspecified time (when the user may have gone to other pages in the interim) you could look into using cookies.

- 1
- 1

- 1,054
- 8
- 17
Try something like this:
window.onload = function() {
var myValues;
if (document.cookie) {
// get your values onLoad
myValues = document.cookie;
} else {
// set your values
myValues = "..." // your values
document.cookie = myValues;
}
}

- 3,083
- 1
- 28
- 39