Click to See Complete Forum and Search --> : Carrying over variables to popup
neil9999
10-10-2003, 01:58 PM
Hi,
I use var url=location.href to make the variable url the same as the URL of the webpage. What I need is a link which when you click on it opens a popup window. There'll be a textbox with the ID 'address' in the popup, and this should be automaticly filled in with var url from the last page.
Any ideas how to do this?
Thanks,
Neil
nauman73
10-10-2003, 03:46 PM
Hi neil
What I understand from your question, you have one page (say page1.html) which opens a popup (say page2.html). You have a text field in page2.html, your popup page, and you want to display the address of page1.html in that text field. Correct me if I am wrong.
Your solution to this problem is based on the idea of passing a variable from page1.html to page2.html. Well, I am not sure how this variable passing thing will work, but I have another solution.
If your objective is to display the address of page1.html in the text field then you can use following code. Design your page1.html (or whatever you call it) the way you like. In the popup page, add this javascript code.
<script language="JavaScript">
function fillTextBox()
{
var textBox=document.getElementById("address");
textBox.value = window.opener.location.href;
}
</script>
Call 'fillTextBox' function on the load event of your popup page body element.
<BODY onload="fillTextBox()">
Here is how it works.
var textBox=document.getElementById("address");
Variable 'textBox' now contains a reference to the text field whose ID is "address".
textBox.value = window.opener.location.href;
Now we are setting the text to be displayed inside the text box (textBox.value does this). What are we putting in the text box? It is 'window.opener.location.href'. Basically its the address of the page which opens the popup (page1.html in our above discussion). Yes, you dont need to pass the address of page1.html to your popup. The popup can access it itself.
Hope this is what you wanted.
Nauman