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

Discussion in 'Javascript' started by ahmadtx@gmail.com, Jul 8, 2007.

  1. Guest

    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.
     
    , Jul 8, 2007
    #1
    1. Advertising

  2. Koebrah Guest

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

    On Jul 8, 5:33 am, "David Mark" <> wrote:
    > <> wrote in message
    >
    > news:...
    >
    >
    >
    > > 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.
     
    Koebrah, Jul 8, 2007
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Kathryn
    Replies:
    4
    Views:
    355
  2. Jens Peter Hansen
    Replies:
    7
    Views:
    561
    Randy Webb
    Jun 19, 2004
  3. Arvin Portlock
    Replies:
    4
    Views:
    286
    Arvin Portlock
    Jul 12, 2004
  4. Adam
    Replies:
    8
    Views:
    450
  5. pasupathy
    Replies:
    0
    Views:
    174
    pasupathy
    Mar 30, 2006
Loading...

Share This Page