I'm having trouble validating a form, but the way I'm trying, I do not know if it's possible, can anyone give me strength?
I have a form with two buttons submit
.
And in the form
tag I'm putting onsubmit = "checa_formulario()"
However, one of the buttons should perform submit without entering this onsubmit
function, but the other button should perform this function.
I tried calling this function in the onclick
of the button I want to run the function, but then it ran the function, but regardless of the result, it performed the submit.
I should use pure javascript.
Could anyone help me?
Thank you in advance!
EDITI have two buttons:
<button type="submit" name="submit" value="1">
<button type="submit" name="submit" value="2">
The button with value = 1
, when clicked, should enter the checa_formulario()
function.
Now the button with value = 2
, when clicked, should not execute the checa_formulario()
function, but should submit.
I'm calling the function inside the onsubmit
in the form tag, since the two buttons should perform submit, the difference between one and the other is that one does validation and the other does not.
<form method="POST" action="arquivo.php" onsubmit="return checa_formulario()">
And this is the function:
if (document.getElementById('descri_icon').value.length < 10) {
alert("Erro");
return (false);
}
This id, descri_icon
is a textarea
, and the only check is to see if it has the minimum character requested, but this, if the button with value = 1
is clicked.