I have a form very similar to the one below. This is just a demo but it illustrates the doubt I have.
<!DOCTYPE>
<html>
<head>
<title>Formulario</title>
</head>
<body>
<form id="CreateForm" action="/create" method="post">
<div>
<label for="campo1">Campo1</label>
<input type="text" id="campo1" name="campo1">
</div>
<div>
<label for="campo2">Campo2</label>
<input type="text" id="campo2" name="campo2">
</div>
</form>
<button type="submit">
Enviar
</button>
</body>
</html>
How can I do so that when I click on the button the form is submitted without using javascript?
In HTML5 a new mechanism was introduced to be able to separate the form elements (buttons, inputs, etc) from the form. The attribute
form
associates a control with a<form>
:It is only necessary to assign the same id of the form in the attribute
form
of the element.Another solution would be this:
Font
Another option using jQuery