How can I start form validation using HTML5 before executing the script?
html
<form action="#"> <input id="a" type="number" max="10" required> + <input id="b" type="number" max="10" required> = <input id="c" type="number" /> <button id='sub' type="submit">Посчитать</button> </form> js
function calc () { var a = $('#a').val(); var b = $('#b').val(); var c = a + b; $('#c').val(c); } console.log($('#a').val()); $('#sub').click(function(){ console.log('click') calc(); }) Now, if you click on the Calculate button, the result will be displayed first, and then a message will appear about the invalid value.
It is necessary that when I enter numbers and click Calculate , standard validation first occurs, and then the script is executed.
PS: in the original script I use jq