Anant
Anant

Reputation: 11

Open a new window and submit a form with a single click

when i click on submit button then :

  • first : open a new window to display process (by ajax call)
  • second : submit current form (processing time consuming job)

    on Click of submit following JQuery function is being called :

    function submitForm(){
        window.open('displayGetStatus.action?id=' + p_id ); 
        $("#frmStartSomeTask").attr("action","executeDatabaseOperation.action").submit();
    }
    

    Result : second window is opened and waiting for process to start but form on first window is not submitted so process is not started.

    Please help how can i get this ?

    Thanks in advance.

    Upvotes: 1

    Views: 1532

  • Answers (2)

    mibbler
    mibbler

    Reputation: 415

    So you want to open a window and then submit a form?

    If so, your submit functionality doesn't look right. It's actually very simple to submit a form using plain Javascript...

    function submitForm() {
        window.open('displayGetStatus.action?id=' + p_id );  
        document.getElementById("frmStartSomeTask").submit();
    }
    

    Upvotes: 0

    Levi Botelho
    Levi Botelho

    Reputation: 25234

    Add the window.open call to the onsubmit of the form. In pure JS...

    document.getElementById(frmStartSomeTask).onsubmit = function () {
        window.open('displayGetStatus.action?id=' + p_id ); 
    }
    

    you can modify this for jQuery if you so desire:

    $("#frmStartSomeTask").submit(function () {
        window.open('displayGetStatus.action?id=' + p_id ); 
    }
    

    Upvotes: 2

    Related Questions