Greasy Fork is available in English.

Discussions » Development

Submit button not submitting the form after enabling userscript.

§
Posted: 16.05.2020
Edited: 16.05.2020

Submit button not submitting the form after enabling userscript.

Whenever I enable my userscript, do some data entry on the form and then hit the submit button, the form doesn't get submitted. But if I disable the userscript and then reload the page, then the submit button submitting the form.

What I want to achieve is this script will detect empty textbox with id ending with bahr and will not let user go further without filling that textbox. So this got nothing to do with the submit button. Nevertheless, this problem occuring.

Note: The form is on a iframe.

// ==/UserScript==

$(document).ready(function() { var txtbox = $("input[id$='bahr']"); function required(txtbox) { if (txtbox.value.length == 0) { return false; } else { return true; } } });

wOxxOmMod
§
Posted: 16.05.2020

The posted fragment doesn't do anything so the problem may be in the metadata header. For example there's a @require for jQuery that conflicts with the page.

§
Posted: 17.05.2020

Hello, thanks for your reply. But is there any way to achieve what I want by using vanilla JS?

§
Posted: 17.05.2020

maybe this can do what you want ?

$(document).ready(function() {
    var txtbox = document.querySelector("input[id$='bahr']");
    var button = document.querySelector("??");//what your sumbit button is?
    function check() {
        if (txtbox.value.length == 0) {
            button.disabled = true;
        }
        else {
            button.disabled = false;
        }
    }
    check();
    txtbox.addEventListener('input',check);
});

Post reply

Sign in to post a reply.