How to continue execution after submitting the form?

I am writing a simple form submission function for a specific site. The script fills out the specific form on the current page and submits the form. He SHOULD also fill out the second form, which appears after sending the first form and submitting this form.

These are two forms that you must fill out and submit.

The problem, however, is that on the regular script page, the 1st form is also populated and submits it. After submitting, however, the script stops working! I want to continue execution!

I did this by mistake on a 2-frame page! most pages have no frames!

function FillFirstForm(){
    doc=document;
    //Some code removed from above...Fill Values
    doc.forms[0].name.value = answerarray[1];
    doc.forms[0].address.value = answerarray[2];
    doc.forms[0].phone.value = answerarray[3];
    doc.forms[0].username.value = answerarray[4];

    //And Press Button
    doc.forms[0].submit.click();

    iTimer=setInterval(FillSecondForm,5000);
    return true;
}

function FillSecondForm(){
    clearInterval(iTimer);
    doc.forms[0].tags.value = answerarray[5];
    doc.forms[0].reference.value = answerarray[6];
    document.forms[0].submit.click();
    return true;
}
+3
source share
3 answers

, . .

, Ajax. , .

- jQuery form plugin. .

+2

FillSecondForm() .

0

AJAX, .

- :

function FillFirstForm() {

    var post_data = 'name='+escape(answerarray[1]);
    post_data += '&address='+escape(answerarray[2]);
    post_data += '&phone='+escape(answerarray[3]);
    post_data += '&username='+escape(answerarray[4]);

    // TODO: make this cross browser :)
    var req = new XMLHttpRequest();

    req.onreadystatechange = function() {
        if ( req.readyState == 4 ) { // The request has finished
            if ( req.status == 200 ) {
                FillSecondForm();
            }
            else {
                // Deal with errors here
            }
        }
    };

    req.setRequestHeader("Content-type","application/x-www-form-urlencoded");
    req.open('POST', '/submit_url', true);
    req.send(post_data);
}

W3 AJAX : http://www.w3schools.com/ajax/ajax_xmlhttprequest_create.asp, .

0

Source: https://habr.com/ru/post/1752959/


All Articles