button, empty fields (and o" /> button, empty fields (and o" /> button, empty fields (and o"/>

HTML/JavaScript: Execute form submit checks on button-press; is it possible in an elegant way?

32 Views Asked by At

I wrote an input form that has input elements with the required attribute set.

So when pressing an <input type="submit" /> button, empty fields (and other violations) are complained about.

However when I use an <input type="button" onClick="something()" /> button, the function is called even if the required input is empty.

Example input field:

<input id="customer-name" type="text" name="i.user.name" size="25" maxlength="40" placeholder="Name" pattern="^[^ ]..+$" required="required" />

Is there a way to execute what a submit button would do without adding a submit button? I mean not repeating the logic in JavaScript as indicated in https://stackoverflow.com/a/11380269/6607497.

Basically while testing I wrote the code (HTML, CSS, JavaScript) in a local file, loaded in a browser. So an actual submit button would be tricky at least (IMHO).

0

There are 0 best solutions below