Results 1 to 3 of 3

Thread: How to close the popup window when submitting the form?

  1. #1
    Join Date
    Aug 2008
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default How to close the popup window when submitting the form?

    How to close the popup window when submitting the form?

    I have a sample.jsp. In that page one button is there.
    when button pressed, open popup window contains one "text box" and one " submit button". when "submit" button pressed, call the "servlet" in this popup window and then close the "popup" window.

    <SCRIPT LANGUAGE="JavaScript">




    <!-- Begin

    var X = 200; // change the # at the left for a fixed X co-ordinate to accommodate browsers other than IE or NS

    var Y = 200; // change the # at the left for a fixed Y co-ordinate to accommodate browsers other than IE or NS



    if (navigator.appName.indexOf("Netscape")!=-1) {

    document.captureEvents(Event.MOUSEMOVE)

    function getcoords(e) {

    X = parseInt(e.screenX) - 80; // change the # at the left to further adjust the left-margin depending on the size of the window

    Y = parseInt(e.screenY) - 60; // change the # at the left to further adjust the top-margin depending on the size of the window

    return true;}

    document.onmousemove = getcoords;



    function openWin() {



    if (navigator.appName.indexOf("Microsoft")!=-1) {

    X = parseInt(event.screenX) - 80; // change the # at the left to further adjust the left-margin depending on the size of the window

    Y = parseInt(event.screenY) - 60; } // change the # at the left to further adjust the top-margin depending on the size of the window

    display=window.open('','NewWin','menubar=0,locatio n=no,status=no,directories=no,toolbar=no,scrollbar s=yes,height=30,width=230')



    message="<font face='verdana, arial, helvetica, san-serif' size='2'>";


    message+="<form name='form1' action='./SaveFile' onsubmit='form1.submit(); self.close();' >";



    message+="Enter Query Name:";

    message+="<input type='text' name='query_name' />";

    message+="<input type='submit' value='GO'/>";

    message+="</form></font>";

    display.moveTo(X,Y);

    display.document.write(message); }

    }



    // End -->

    </script>



    The above code didn't call the "servlet" but cose the popup window.

    I want to call the "servlet" and then close the popup window.

    plz help me, how to close the popup window after submitting the form in popupwindow.

  2. #2
    Join Date
    Sep 2005
    Location
    India
    Posts
    1,626
    Thanks
    6
    Thanked 107 Times in 107 Posts

    Default

    The "onsubmit" event fires when a FORM is about to be submitted. You need to close the popup only after the form submission completed properly, in your case the you are not correctly submitting the form but the window closes.

    You can do it something like this. Let the user submit the form by pressing the submit button then in your backend processing page ('./SaveFile') you'll do the processing and send some JS code for alerting the message you want and for closing the window, which will do the job.

    I don't know JSP so unable to provide a working example but you can build one based on the above mentioned idea without much trouble.

    Hope this helps.

  3. #3
    Join Date
    Aug 2008
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by codeexploiter View Post
    The "onsubmit" event fires when a FORM is about to be submitted. You need to close the popup only after the form submission completed properly, in your case the you are not correctly submitting the form but the window closes.

    You can do it something like this. Let the user submit the form by pressing the submit button then in your backend processing page ('./SaveFile') you'll do the processing and send some JS code for alerting the message you want and for closing the window, which will do the job.

    I don't know JSP so unable to provide a working example but you can build one based on the above mentioned idea without much trouble.

    Hope this helps.

    thanks for your suggestion.
    I wrote alert() inbetween submit() and close() in a single function and then call that function.
    then problem solved

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
  •