简体   繁体   中英

How to complete a form and press submit on page load

I want to write a simple Greasemonkey script, to complete and submit this form every time the page loads.

Enter a predefined email address (email@gmail.com) into the script, then submit it each time

<div class="col-md-4">
    <label for="Content_C001_LI_02_txtEmail">Send proof of delivery email to:</label>
</div>
<div class="col-md-5">
    <input name="ctl00$Content$C001$LI_02_txtEmail" type="text" value="email@gmail.com" id="Content_C001_LI_02_txtEmail" class="form-control" onkeypress="return clickButton(event,'Content_C001_LI_02_btnSend')"><span id="Content_C001_ctl23" style="display:none;"></span>
</div>
<div class="col-md-3">
    <button onclick="if (typeof(Page_ClientValidate) == 'function') Page_ClientValidate('LI_02'); __doPostBack('ctl00$Content$C001$LI_02_btnSend','')" id="Content_C001_LI_02_btnSend" type="button" class="btn btn-primary btn-inline-label" validationgroup="LI_02">Send</button>
</div>

Once the form has been submitted, this piece of code changes.

So I will need to figure out how to only run the script if it hasn't already been submitted before.

<div id="Content_C001_ctl00" class="alert alert-success" style="display:none;">

to

<div id="Content_C001_ctl00" class="alert alert-success">
Proof of delivery has been successfully emailed to email@gmail.com <br>

Your help is much appreciated! :)

Something like this maybe?

document.addEventListener ("DOMContentLoaded", checkSubmitEmail);

function checkSubmitEmail(){
    var myEmail = 'vns@gmail.com';

    // 1- check if email has been submitted
        var submitted = document.getElementById('Content_C001_ctl00').innerHTML.startsWith('\nProof of delivery has been successfully emailed to ' + myEmail);

    // 2- if not continue
        if (!submitted){
            // 3- fill in email
                document.getElementById('Content_C001_LI_02_txtEmail').value='' + myEmail;

            // 4- click button
                document.getElementById('Content_C001_LI_02_btnSend').click();
        }

}

It's hard to tell precisely, but a cookie may be what you are looking for here.

MDN's documentation on the JS Cookie interface

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM