Search code examples
javascriptjquerytampermonkey

call function When Submit is Clicked


Hello guy's im trying to call a Function But after i Click on Submit but there is no ID for the submit here what i got :

<input type="submit" name="save" value="Continue" onclick="return validateFrm();" class="btn primary-btn btn-ctnue row alignCenter" autocomplete="off">

so i want it to be like this for example :

if Submit Clicked then Run this : function example() { alert('Yay!'); )

Anyidea How to do it on JavaScript/Jquery

Ps: There a lot of Submit so i want this specific Submit


Solution

    1. Select the submit button using CSS selector input[name=save]
    2. Add listener to fire on click event and pass the function to execute.
    document.querySelector("input[name=save]").addEventListener("click", function(){
        alert('Yay!');
    });