2

I want to pull a value using ONLY javascript from another page. I tried with common javascript file between pages, but i was failed... Here's example...

Page 1: 1. A textfield(1) on PAGE 1 (its empty) 2. A button(1) on PAGE 1

Page 2: 1. A textfield(2) on PAGE 2 2. A button(2) on PAGE 2

Working : 1. On a button(1) click on PAGE 1, a new window opens i.e. PAGE 2 and the old window will be intact(will not be closed) 2. After opening new window, i have entered some text in textfield(2) on PAGE 2 2. On a button(2) click on PAGE 2, the value entered in textfield(2) should be inserted into PAGE 1 's textfield(1).

NOTE : If possible with JQuery, then its my secondary choice if javascript doesnt works...

check this image : http://i25.lulzimg.com/54e219.jpg

Mayur
  • 33
  • 8

4 Answers4

1

First off, as Josh mentioned, jQuery is just a library written in javascript. Secondly, assuming you are opening the second page in a new window, you want to use cross window communication with javascript. When you issue your window.open call, it returns a handle to the newly opened window:

var windowHandle = window.open(....);
windowHandle.doStuff() 

You could use this handle to pass data to the other window, for an example check out this post:

Window to Window Communication in js by window name

Hope this helps!

Community
  • 1
  • 1
Justin Beckwith
  • 7,686
  • 1
  • 33
  • 55
1

Since it is missing: Jquery Solution

Script on parent page:

$("#button1").click(function () {
    window.open(url, "title", "width=400,height=400");
    return false;
});

Script on child page:

$("#button2").click(function () {
    window.opener.$("#textbox1").val($("#textbox2").val());
    return false;
});
rlemon
  • 17,518
  • 14
  • 92
  • 123
0

Assuming both pages are served from the same domain, you can use window.opener to refer to page1 from page2:

window.opener.document.getElementById("textfield1").value
    = document.getElementById("textfield2").value;
Frédéric Hamidi
  • 258,201
  • 41
  • 486
  • 479
0

Although I don't see why you don't just enter the text in textbox1 rather than copyinging it from #2....

Rather than opening a new window, put the contents from this "second page" in the first page (watch out for element name overlaps) contained inside a div declared to be hidden. On clicking the first button, make the div visible. On clicking the second button, set the text from the second box to the first box, and re-hide the div.

This can all be done pretty simply with javascipt, even simpler with jquery (still javascript).

yoozer8
  • 7,361
  • 7
  • 58
  • 93