View Full Version : Pop up window "variables" sent from first html page?
kramer336
10-24-2002, 04:54 PM
:thumbsup:
Hello to the good people at Coding Forums!
I am an intern at austinweddings.com. I am really interested in learning JavaScript programming. I came across an interesting problem and thought someone can help....
The first HTML page has a simple popup command....
http://www.austinweddings.com/XXXTest.htm
and the second is the Pop Up window.
http://www.austinweddings.com/XXXTest2.htm
Different vendors have different email addresses.
Question:
Can the first HTML page send the vendors email address to the second "pop up window"
Reason for question. .
Currently the site uses the simple "mailto:" command. But this will not do because most viewers of the site do not have email configured. So having a pop up window with an email form would solve this problem and having the "TO:" section of the form already filled out would help the visitors dramatically.
Can anyone please help?
ps. here is a screen shot of the final look...
http://www.austinweddings.com/images/fakevendor.jpg
:D
beetle
10-24-2002, 05:14 PM
I wrote a function (http://www.codingforums.com/showthread.php?s=&threadid=4555&highlight=parseGetVars) a while back to help with stuff like this.
in XXXtest.htm<a href="XXXtest2.htm?email=fakevendor@austinweddings.com" onClick="window.open(this.href,'NewWindow','resizable=yes,copyhistory=yes,width=410,height=375');">e-mail link</a>Ok, now, in the popup page, we need to handle this data.
XXXtest2.htm:<script>
function parseGetVars() {
var getVars = new Array();
var qString = top.location.search.substring(1);
var pairs = qString.split(/\&/);
for (var i in pairs) {
var nameVal = pairs[i].split(/\=/);
getVars[unescape(nameVal[0])] = unescape(nameVal[1]);
}
return getVars;
}
var g = parseGetVars();
</script>
<body onLoad="document.forms[0].sender1.value = g['email'];">
kramer336
10-24-2002, 08:02 PM
Beetle,
Thanks for your advice... but one prob... The new pop up window doesnt open "pageURL not found." I updated the page and you can check it out...
http://www.austinweddings.com/XXXTest.htm
any suggestions....???
beetle
10-24-2002, 08:29 PM
Well, I can see that you directly cut & pasted my HTML, which gets a bit messed up by this forum.
1) remove the space in 'this. href'
2) remove the linebreak in the middle of 'width'
3) Add the text in red below
<a href="XXXtest2.htm?email=fakevendor@austinweddings.com" onClick="window.open(this.href,'NewWindow','resizable=yes,copyhistory=yes,width=410,height=375');return false;">e-mail link</a>
kramer336
10-24-2002, 08:32 PM
got it!
Thanks Beetle, you da Bomb :thumbsup:
kramer336
10-24-2002, 08:57 PM
:cool: Beetle,
Now that the email box is auto filled... Is it easy to also send a string of text to the top of the "pop-up" form or html page....
What I'm getting at is.....
The form could possible say the name of the vendor....
Example...
"Email (Fake Vendor Name) with your questions today."
This would help make the form more personalized....
Any suggestions?
Sincerely,
Steve
beetle
10-24-2002, 09:20 PM
Well, the way my parseGetVars function is setup is to dissect a properly formatted querystring, which sends GET variables to the next page. A properly formatting querystring is comprised like this
? - start of querystring
& - separates name/value pairs
name=value - format for variables
So, for example, if you wanted to send the email address AND a title for the page...you'd do this...
href="XXXtest2.htm?email=fakevendor@austinweddings.com&title=Whatever"
Then, in the next page...access the variable by it's name through the array that we assigned the GET variables to. In our case, that variable is g
top.title = g['title'];
So, you can send as many variables in the querystring as you like (although, the maximum is 512 characters, I believe...)
kramer336
10-24-2002, 09:25 PM
thanks a lot Beetle, I'm learning from your advice and suggestions. :p
kramer336
10-24-2002, 09:48 PM
I understand the first part... very cool...
But...
Im having trouble calling the variable in the second html page.?
Im putting the code like this...
<body onLoad="top.title = g['title'];">
but i think im wrong.
:(
beetle
10-24-2002, 10:06 PM
What I recommend is make a function that will handlees all the variables once the page loads...<script>
function setPageVars() {
document.forms[0].sender1.value = g['email'];
document.title = g['title'];
// etc, etc....
}
</script>
<body onload="setPageVars();">P.S. Sorry...title is a sub-object to document, not the window
kramer336
10-24-2002, 10:14 PM
Beetle,
Here is what i came up with and its not working....
<script>
function setPageVars() {
document.forms[0].sender1.value = g['email'];
document.title = g['title'];
var getVars = new Array();
var qString = top.location.search.substring(1);
var pairs = qString.split(/\&/);
for (var i in pairs) {
var nameVal = pairs[i].split(/\=/);
getVars[unescape(nameVal[0])] = unescape(nameVal[1]);
}
return getVars;
}
</script>
I put the script in the head of the document and then called it... with...
<body onload="setPageVars();">
but nothing...
hmmmm please help.
beetle
10-24-2002, 10:43 PM
Whoa whoa whoa. Why are you breaking things up? It should look like this...<script>
function parseGetVars() {
var getVars = new Array();
var qString = top.location.search.substring(1);
var pairs = qString.split(/\&/);
for (var i in pairs) {
var nameVal = pairs[i].split(/\=/);
getVars[unescape(nameVal[0])] = unescape(nameVal[1]);
}
return getVars;
}
function setPageVars() {
var g = parseGetVars();
document.forms[0].sender1.value = g['email'];
document.title = g['title'];
// etc, etc....
}
</script>
</head>
<body onload="setPageVars();">
kramer336
10-24-2002, 10:54 PM
ok ok ok ,,, cool ... i got it... but how do i plug it in like this...
VARIABLE HERE's Contact Page
beetle
10-24-2002, 11:08 PM
function setPageVars() {
var g = parseGetVars();
document.forms[0].sender1.value = g['email'];
document.title = g['title'];
document.getElementById('hello').innerText = g['name']; // Or whatever variable you use
// etc, etc....
}
<span id="hello"></span>'s Contact PageGot that?
kramer336
10-24-2002, 11:24 PM
Ok, im confused. . . Can you please look at the page http://www.austinweddings.com/XXXTest2.htm
and create a mock page with the code inserted in the right places. I think that is my problem.
Thanks
Steve :eek:
kramer336
10-24-2002, 11:26 PM
ps. my aim name is "enigmarep" and my messenger name is enigmarep@hotmail.com ..
kramer336
10-25-2002, 04:37 PM
Thanks.... the problem is fixed. :thumbsup:
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.