I thought I knew JavaScript pretty well but maybe not.
Basically, what I’m attempting is having one document (parent) open a second window (child) and have the variable values entered in the parent document to be transferred to the second.
I looked at a great many JavaScript tutorials and couldn’t find a solution.
Any help would be appreciated.
this article Boutell.co.uk | Payday Loans Paid Out Instantly suggests using window.name property if you are unable to do communication via a server-side script.
What I’ve done is pass the variables in the url like this -
window.open(“Print.aspx?ext=’” + extString + “’&PPI=’” + strPrintPPIs + “’”);
And in the called window get the URL.
var fullURL = window.location.href;
Then have javascript parse out the variable like this -
strPPI = fullURL.substring(fullURL.indexOf(’&’) + 6, fullURL.length - 2)
A better way to do this is to pass the parameters on the anchor string, so you don’t end up polluting your server logs with client-side junk.
window.open( "foo.html#var1=" + var1 + ";var2=" + var2 );
Of course you can use whatever delimiters you want. Then in your new window
var params = window.location.hash;
And parse the stuff out of the params string however you like. jQuery has a number of good parameter parsers for query and anchor strings so you don’t have to reinvent the wheel.
Okay, let’s say I didn’t have too much success with those.
Maybe I should show something specific. (See next posting)
Calculator 1 (passvar1) has three input boxes and when a number is input into all 3 boxes, clicking “Calculate Sum” puts the total of those 3 numbers into the output box.
http://www.1728.com/passvar1.htm
When “Calculate Product” is clicked, a new window is opened and it displays the numbers six, seven and eight with their product 336.
Basically, how do I get the values of the 3 numbers (“num1” “num2” “num3”) into calculator2?
(The URL of the second calculator (the new window) doesn’t have to be shown but for those that want it: http://www.1728.com/passvar2.htm)
(Thanks for the replies so far)