Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Sep 2007
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    BUTTON THAT SUBMITS FORM DATA TO A NEW WINDOW; without modifying the form tag.

    BUTTON THAT SUBMITS FORM DATA TO A NEW WINDOW; without modifying the form tag.

    I am trying to post data to a new window; with using the form tag.




    One method among many I have found on the net.
    function postToPopup( uname, pwd )
    {
    var form = document.getElementById("hiddenForm");
    form.username.value = uname;
    form.password.value = pwd;
    window.open( "", "MYPOPUP", "width=600,height=400" );
    form.submit();
    }


    <form id="hiddenForm" target="MYPOPUP" method="post" action="http://anyOldSiteAtAll.com/somepage.xxx">
    <input type="hidden" name="username"/>
    <input type="hidden" name="password"/>
    </form>

    The issue with this is that I have no access to the main form; this needs to happen without modifying the form tag at all. It seems like all the solutions what you to modify the form tag.
    -------------------------------------------------------------------






    I did try this out in the button instead of modifying the form tag but i can only pass values via get and i can't grab any form elements to pass on this way.
    <script type="text/javascript">
    // M- Opens up new window and not a TAB.
    function OpenForm(x, w, h, name, URL) {
    var settings = 'width=' + w + ',height=' + h + ',scrollbars=yes,toolbars=no, directories=no,left=0, top=0';
    while (URL.indexOf(" ") != -1)
    URL = URL.replace(" ", "%20");
    mywin = "win" + x;
    mywin = window.open(URL, name, settings);
    }
    </script>

    This works but will not do a submit to a a new window; it just opens one up. I can pass values in a query string though but no post.
    <input type='button' name='PhoneCall' id='PhoneCall' value='Phone Call' onClick="OpenForm(4,'800','500','OOSTITLEPhone','TITLE_PHONECALL_frm.aspx?TitleID=869&CustPhone=111-222-3333');">
    ------------------------------------------------------------------







    I think if I can combine the two into one it might work; something like this:
    <script type="text/javascript">
    // M- Opens up new window and not a TAB.
    function postToPhone(x, w, h, name, URL) {
    var settings = 'width=' + w + ',height=' + h + ',scrollbars=yes,toolbars=no, directories=no,left=0, top=0';
    while (URL.indexOf(" ") != -1)
    URL = URL.replace(" ", "%20");
    mywin = "win" + x;
    mywin = window.open(URL, name, settings);

    // can do some form validation here then submit.

    form.submit();
    }
    </script>


    <input type='button' name='PhoneCall' id='PhoneCall' value='Phone Call' onClick="postToPhone(4,'800','500','OOSTITLEPhone','PHONECALL_frm.aspx');">

    With this I am not sure how or if it will just post all the request.form data to the new page? Do I have to grab each element I want to pass? Like a regular form post to itself would it just pass all the form data over?

    This is what I am unsure about.



    Anyone have any ideas?

    Thanks.

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,965
    Thanks
    79
    Thanked 4,429 Times in 4,394 Posts
    Do you mean you can't modify the <form> tag directly? Or you can't even modify it with JavaScript?

    Because clearly you could have code such as
    Code:
    <input type="button" value="Phone Call"
           onclick="var f=document.forms[0]; f.target='MYPOPUP'; f.submit();" />
    assuming that the <form> is in the same page as your button.

    (And you can have a name and/or id on that button, but they won't ever be used.)
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #3
    New to the CF scene
    Join Date
    Sep 2007
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I am trying to figure out how to put that into working with a function so you can validate with JavaScript and all that. If it passes then we open up the page but if not we stop there and messagebox them.

    I would actually need it to open the page PHONECALL_frm.aspx in the new window upon passing validation and there i can use the phone number and any other fields I grabbed and needed from the parent form.


    <input type="button" value="Phone Call"
    onclick="var f=document.forms[0]; f.target='MYPOPUP'; f.submit();" />

    Can this submit to a function like SubmitPhone {

    // do validation here

    submit here.

    }



    There are so many different ideas about how to do this on the net that it gets confusing as to which is the best way.

    Thanks.

  • #4
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,965
    Thanks
    79
    Thanked 4,429 Times in 4,394 Posts
    ???

    "submit to a function"??? That is semantic nonsense. You submit forms. You call or invoke functions.

    Anyway, I *THINK* the answer is "of course":
    Code:
    <input type="button" value="Phone Call" onclick="SubmitPhone()"/>
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #5
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,068
    Thanks
    0
    Thanked 256 Times in 252 Posts
    Code:
    function postToPopup( uname, pwd )
    {
    	var form = document.getElementById("hiddenForm");
    	form.username.value = uname;
    	form.password.value = pwd;
    	form.target = 'MYPOPUP';
    	window.open("", form.target, "width=600,height=400");	
    	form.submit();
    }
    
    function SubmitPhone() {
       ...
       ...
       //this function needs to return true or false
    	
    }
    Code:
    <input type="button" value="Phone Call" onclick="SubmitPhone() && postToPopup('xxxx', '*****')" />
    Replace the parameters passed to postToPopup() accordingly.
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •