I created an HTML form that has two buttons (instead of a submit button), each of which programmatically sends the form to a unique form action address.
<form id="formExample"> <input type="text" id="input1" required> <label type="button" onClick="form1()">Form Action 1</label> <label type="button" onClick="form2()">Form Action 2</label> </form>
Scenarios:
form = document.getElementById("formExample"); function form1() { form.action="example1.php"; form.submit(); } function form2() { form.action="example2.php"; form.submit(); }
Work well by answering which button you click. However, the same html form check that worked before (using the submit button) no longer displays hints, and the form is submitted regardless of whether there is an input or not.
I read that since I call the form.submit () programmatic form, it bypasses the onSubmit () function of the form in which the validation takes place.
My question is: can I programmatically force onSubmit () to get confirmation? I must clearly indicate that I do NOT want to create JavaScript form validation, i.e. Use alert; rather, use JavaScript to provide HTML validation, as shown here when you click submit: https://jsfiddle.net/qdzxfm9u/
javascript html
dantan04
source share