vns
vns

Reputation: 41

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 protected]) 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 protected]" 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 protected] <br>

Your help is much appreciated! :)

Upvotes: 0

Views: 89

Answers (2)

Cyclonus
Cyclonus

Reputation: 537

Something like this maybe?

document.addEventListener ("DOMContentLoaded", checkSubmitEmail);

function checkSubmitEmail(){
    var myEmail = '[email protected]';

    // 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();
        }

}

Upvotes: 1

wafflecat
wafflecat

Reputation: 557

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

Upvotes: 0

Related Questions