Reputation: 3
Why "<button onclick="submit()"> Submit</button>
" don't work for validations?
and why "<input type="submit" value="submit">
" works?
<form action="#" method="post">
<input type="text" name="val" required><br>
<button onclick="submit()">Submit</button>
<input type="submit" value="submit">
</form>
Upvotes: 0
Views: 443
Reputation: 2830
That is going to try to call a javascript function called submit
. I assume you don't have such a function.
If you wanted to use javascript to submit the form, you would create a submit function like so:
function submit() {
document.getElementById("form_ID").submit();
}
And you'd have to give your form an ID. I've used form_ID
in the function, but you can choose something else.
Upvotes: 3