None of the “Similar quiestons” helped me
I have a button that I need to disable once it was clicked:
<button class="button" type="submit" id="saveButton" hidden="hidden" style="display:none">submit</button>
<input onclick="validator()" id="handleSaveButton" class="button" type="button" value="my button value">
Here’s how I do it:
function validator(){
$(".buttons :input[value:'my button value']").prop("disabled",true)
...
//something else goes here
...
document.getElementById("saveButton").click();
}
Now this works but my page also has required fields. And if those aren’t filled, you have to refresh the whole page to make save button available again.
I’m looking for a solution to
- Make my button disabled once clicked
- Make it enabled again if required fields are not filled
Thanks. Please note that I cannot change the structure with hidden submit and actual button
2
Answers
Somebody posted an answer but it got deleted unfortunately. Here's their solution:
Worked great for me
There is no need of complicated selector inside JQuery. Just differ elements by className: .buttons.handler And .buttons.save.
After that, you can write this simple JS code. And don’t forget, jQuery always return a collection of objects with a length. That’s why i used $()[0] to handle the first element.
Please Don’t forget to mark as solved