JavaScript: How to post a form to frame in a popup

A

ahmadtx

First, I really appreciate anyone's help in advance.

In short, I have a page that contains a form, which upon submission
I'd like to popup a windw that contains two frames. The form should
post to that 2nd frame ONLY.

I know how to popup a window, and post the form to it; but I can't
seem to post it to a frame of that window.

I'd share my code, but we're talking about a crap load of code here.
Nonetheless, here's a shot at it:

The main page has a form, which reads:
<form id="hs_form" name="hs_form" method="post" action="...some
URL ..." target="lowerFrame" onSubmit="if (!buttonClicked) return
false>
....
<input type=button value="Submit Search"
onClick="NewWindow('popupframe.shtml','myWin',1000,600,'no');
buttonClicked=true; setTimeout('document.hs_form.submit()',500)" />

The NewWindow function looks like this:
/* Cross-Browser Window Popup Script */
var win = null;
function NewWindow(mypage,myname,w,h,scroll){
LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
settings = 'height='+h+',width='+w+',top='+TopPosition
+',left='+LeftPosition+',scrollbars='+scroll+',resizable'
win = window.open(mypage,myname,settings)
}


The popupframe.shtml has some serious crap about parsing the query
string. Still, here it is:

function getSearchAsArray() {
var minNav3 = (navigator.appName == "Netscape" &&
parseInt(navigator.appVersion) >= 3)
var minIE4 = (navigator.appName.indexOf("Microsoft") >= 0 &&
parseInt(navigator.appVersion) >= 4)
var minDOM = minNav3 || minIE4 // Baseline DOM required for this
function
var results = new Array()
if (minDOM) {
var input = unescape(location.search.substr(1))
if (input) {
var srchArray = input.split("&")
var tempArray = new Array()
for (i = 0; i < srchArray.length; i++) {
tempArray = srchArray.split("=")
results[tempArray[0]] = tempArray[1]
}
}
}
return results
}

function loadFrame(varName,fName) {
/*
varName is the "name" part of the name/value pair in the query-string/
URI
fName is the name of the frame passed.
*/
var url = "aboutus.shtml";
if (location.search) {
var srchArray = getSearchAsArray()
if (srchArray[varName]) {
var url = srchArray[varName]
//alert (url);
}
}
//alert(top.opener.document.forms[0].target);
parent.frames[fName].location = url;
}

The actual frameset of popupframe.shtml is:

<frameset rows="127,*" onLoad="loadFrame('content', 'lowerFrame')">
<frame src="topFrame.shtml" scrolling=no marginwidth=0
marginheight=0 name="upperFrame" id="upperFrame">
<frame src="javascript:' '" name="lowerFrame" id="lowerFrame">
</frameset>


Again, I'm trying to submit the search from the main page to the
popup's "lowerFrame" frame.
Oh yeah, topFrame.shtml is my banner page (kinda like Google's image
search results ... after you click on an image, of course).

BTW, the commented line that reads:
//alert(top.opener.document.forms[0].target);
returns a privacy/illegal action exception of some sort. Otherwise,
the intention was to change the target of the main page's form to be
the intended frame.

Again, any help would be greatly appreciated. After several hours on
a couple of days, I'm just too fried to see straight.

Thank you in advance.
 
K

Koebrah

First, I really appreciate anyone's help in advance.
In short, I have a page that contains a form, which upon submission
I'd like to popup a windw that contains two frames. The form should
post to that 2nd frame ONLY.
I know how to popup a window, and post the form to it; but I can't
seem to post it to a frame of that window.
I'd share my code, but we're talking about a crap load of code here.
Nonetheless, here's a shot at it:
The main page has a form, which reads:
<form id="hs_form" name="hs_form" method="post" action="...some
URL ..." target="lowerFrame" onSubmit="if (!buttonClicked) return
false>
...
<input type=button value="Submit Search"
onClick="NewWindow('popupframe.shtml','myWin',1000,600,'no');
buttonClicked=true; setTimeout('document.hs_form.submit()',500)" />

This is crazy. What if the user submits the form without clicking your
button (eg with the enter key?) And what is the significance of 500ms? Is
that the assumed loading time of the frameset? It is clear at this point
that you need to rethink the problem.


The NewWindow function looks like this:
/* Cross-Browser Window Popup Script */
var win = null;
function NewWindow(mypage,myname,w,h,scroll){
LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
settings = 'height='+h+',width='+w+',top='+TopPosition
+',left='+LeftPosition+',scrollbars='+scroll+',resizable'
win = window.open(mypage,myname,settings)
}
The popupframe.shtml has some serious crap about parsing the query
string. Still, here it is:
function getSearchAsArray() {
var minNav3 = (navigator.appName == "Netscape" &&
parseInt(navigator.appVersion) >= 3)
var minIE4 = (navigator.appName.indexOf("Microsoft") >= 0 &&
parseInt(navigator.appVersion) >= 4)
var minDOM = minNav3 || minIE4 // Baseline DOM required for this

This is indeed crap. FYI: minDOM is meaningless at this point. Don't sniff
the navigator object!


function
var results = new Array()
if (minDOM) {
var input = unescape(location.search.substr(1))
if (input) {
var srchArray = input.split("&")
var tempArray = new Array()
for (i = 0; i < srchArray.length; i++) {
tempArray = srchArray.split("=")
results[tempArray[0]] = tempArray[1]
}
}
}
return results
}

function loadFrame(varName,fName) {
/*
varName is the "name" part of the name/value pair in the query-string/
URI
fName is the name of the frame passed.
*/
var url = "aboutus.shtml";
if (location.search) {
var srchArray = getSearchAsArray()
if (srchArray[varName]) {
var url = srchArray[varName]
//alert (url);
}
}
//alert(top.opener.document.forms[0].target);
parent.frames[fName].location = url;
}
The actual frameset of popupframe.shtml is:
<frameset rows="127,*" onLoad="loadFrame('content', 'lowerFrame')">
<frame src="topFrame.shtml" scrolling=no marginwidth=0
marginheight=0 name="upperFrame" id="upperFrame">
<frame src="javascript:' '" name="lowerFrame" id="lowerFrame">
</frameset>

Why is your lower frame using "javascript:''" as its source?


Again, I'm trying to submit the search from the main page to the
popup's "lowerFrame" frame.
Oh yeah, topFrame.shtml is my banner page (kinda like Google's image
search results ... after you click on an image, of course).

So get rid of the banner (and frameset) and your problem will go away.


BTW, the commented line that reads:
//alert(top.opener.document.forms[0].target);
returns a privacy/illegal action exception of some sort. Otherwise,
the intention was to change the target of the main page's form to be
the intended frame.

Leave it commented and forget that idea.


Again, any help would be greatly appreciated. After several hours on
a couple of days, I'm just too fried to see straight.

It sounds like you are fried indeed. But seriously, see the FAQ entry about
how to post a form to a popup window and if you must use a frameset,
generate it on the server, filling in the lower frame's source with whatever
is appropriate, based on the submitted fields. That way your form and
banner will work without script.


Thank you in advance.





I really appreciate your feedback.
I'm redesigning the site, so there's a lot of clean up.
The 500ms was to see if the Object would be there if I waited 'till
the popup was already created.
A feeble attempt, as you have noticed.

Without going into too much detail, I really don't want to give up the
banner part. As an alternative, I've gone ahead and made the menu
item popup the window with two frames, with the top frame being the
banner and the bottom frame containing a cleaner slimmed down version
of what I called the "main page" earlier. Now when someone submits
the form in that bottom frame, it targets itself and I get the end
result. Like you said, I re-thought the whole thing to get what I
want.

Still, though, it kills me that I cannot target a specific frame in a
popup.

Again, thank you for feedback.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,787
Messages
2,569,631
Members
45,338
Latest member
41Pearline46

Latest Threads

Top