There is a form on the first page, by clicking on the button on the page a window opens with a table, and when you double-click on a row from the table, the data should fall into the form fields.

If the form and the table are placed on the same page, then everything works, but if you put the table into another window, which is created by a function, it no longer works.

If I understand correctly, the problem with the globalization of functions, probably.

Here is the code:

Home Page:

<!DOCTYPE HTML> <html> <head> <title>Untitled</title> <meta charset="utf-8"> </head> <body> <button type="button" onclick="NewWindow()">Банки</button> <br /><br /> Bank Name: <br /> <textarea id='bank' cols=56 rows=6></textarea> Bank Adress: <br /> <textarea id='bic' cols=56 rows=6></textarea> <script> var textarea_bank = document.getElementById('bank'), textarea_bic = document.getElementById('bic'); function comm(){ var tmp = new Array(); // два вспомогательных var tmp2 = new Array(); // массива get = new Array(); var url = location.search; // строка GET запроса if(url != '') { tmp = (url.substr(1)).split('&'); // разделяем переменные for(var i=0; i < tmp.length; i++) { tmp2 = tmp[i].split('='); // массив get будет содержать get[tmp2[0]] = tmp2[1]; // пары ключ(имя переменной)->значение } } } function NewWindow() { var textarea_bank = document.getElementById('bank').innerHTML, textarea_bic = document.getElementById('bic').innerHTML; myChildWin = window.open("test.html?bank="+textarea_bank+"&bic="+textarea_bic, "_blank", "toolbar=no, scrollbars=no, resizable=no, top=100, left=100, width=600, height=600"); } </script> </body> </html> 

Table window:

  <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>test</title> </head> <body> <table id="mySuperTBL"> <tr> <td><b>BankName</b> </td> <td><b>BIC</b> </td> </tr> <tr id='1' ondblclick='comm(this)'> <td>Bank</td> <td>Adress</td> </tr> </table> </body> </html> 
  • Maybe using a cookie will help in this situation. - Vyacheslav Kirichenko

3 answers 3

You can do this: http://greenjs.ru/paste/Z1RumvPmu

 var w = window.open(); w.document.write('Hello'); w.message = function(data) { alert(data); //обрабатываем в главном окне }; //вызов в дочернем окне message('Данные'); //передаем данные 

    Pack the data in the URL when creating the window:

     function NewWindow() { var textarea_bank = document.getElementById('bank').innerHTML, textarea_bic = document.getElementById('bic').innerHTML; myChildWin = window.open("test.html?bank="+textarea_bank+"&bic="+textarea_bic, "_blank", "toolbar=no, scrollbars=no, resizable=no, top=100, left=100, width=600, height=600"); } 

    In a new window, double-click to disassemble the incoming line:

     function comm(){ var tmp = new Array(); // два вспомогательных var tmp2 = new Array(); // массива get = new Array(); var url = location.search; // строка GET запроса if(url != '') { tmp = (url.substr(1)).split('&'); // разделяем переменные for(var i=0; i < tmp.length; i++) { tmp2 = tmp[i].split('='); // массив get будет содержать get[tmp2[0]] = tmp2[1]; // пары ключ(имя переменной)->значение } } } 

    get[bank] - данные из textarea "bank" get[bic] - данные из textarea "bic"

    • Thank you, I did as you wrote, but still does not work. I updated the first message, everything is done, as you wrote, or maybe I misunderstood something? - Tachi

    Hello! When I myself studied HTML 3.2 / 4.0 and JS 1.4 / 1.5, I myself came across something similar. Then, if I'm not mistaken, there was an implementation through "_parent" or something like that. Also, there is a property, it seems to be called "referer", that is, contact the initiator of the event.