SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    Free your mind Toly's Avatar
    Join Date
    Sep 2001
    Location
    Panama
    Posts
    2,181
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    pop up window after a form submission

    Hello,

    I would to know how to get a javascript pop up window after I submit a form. I know I can get a normal window to pop up by inserting the target command within the form tag, but I would like to know if I can get a javascript pop up instead.

    Thanks.

  2. #2
    ☆★☆★ silver trophy vgarcia's Avatar
    Join Date
    Jan 2002
    Location
    in transition
    Posts
    21,235
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    You'd have to execute a javascript function with either the form's onsubmit event or the body's onunload event. Here's code for both:
    Code:
    <!--form tag-->
    <form name="form1" method="post" action="page2.htm" onsubmit="javascript:functionName();">
    <!--body tag-->
    <body onunload="javascript:functionName();">
    where "functionName()" is the name of the function you're using to pop up the window.

    --Vinnie

  3. #3
    Free your mind Toly's Avatar
    Join Date
    Sep 2001
    Location
    Panama
    Posts
    2,181
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks, it worked fine... However the submitted information is not getting through, I mean it doesn't show up on the pop up window. Any suggestions?

    Thanks.

  4. #4
    ☆★☆★ silver trophy vgarcia's Avatar
    Join Date
    Jan 2002
    Location
    in transition
    Posts
    21,235
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    If you named your popup window, then do this:
    Code:
    <script language="javascript" type="text/javascript">
    //this will send the form data to the popup window
    function sendFormDataToPopup(popupName, formname) {
     formname.target=popupName;
     formname.submit();
    }
    var win = null;
    //popup window code
    function NewWindow(mypage,windowName,w,h,scroll)
    {
    	LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
    	TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
    	LeftPosition = LeftPosition / 1.01;
    	TopPosition = TopPosition / 1.08;
    	settings = 'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',resizable'
    	win = window.open(mypage,windowName,settings)
    }
    
    //this is the function you call on the form onSubmit event
    function moveEverything(formID, windowName) {
     var tar = formID.action;
     var openIt = NewWindow(tar,windowName,'500','500','no');
     var SFD = sendFormDataToPopup(windowName, formID);
    }
    </script>
    <body>
    <form name="form1" onsubmit="return moveEverything(this, 'PopupWin');">
    Hopefully this will work for you. I've done some things like this before, but usually with the target attribute on forms.

    --Vinnie

  5. #5
    Free your mind Toly's Avatar
    Join Date
    Sep 2001
    Location
    Panama
    Posts
    2,181
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok... what i'm getting right now in the pop up window is the same page the form is located at. Can you tell me what things i have to change, cuz i changed some stuff but it didn't work. I don't know anything about javascript.

    Thanks in advance.

  6. #6
    ☆★☆★ silver trophy vgarcia's Avatar
    Join Date
    Jan 2002
    Location
    in transition
    Posts
    21,235
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    Question:
    If you don't know anything about Javascript, then why are you doing this?

    Also, aside from all of my help, you really should not start opening new windows on people, especially if it's for something like a form submission. Use "target=_blank" just in case people have JS turned off. It would be much easier that way than to try and re-create it all in javascript.

    --Vinnie


Bookmarks

Posting Permissions

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