1
I’m having trouble validating a form, but the way I’m trying I don’t know if it’s possible, someone can give me a strength?
I have a form with two buttons submit
.
And on the tag form
I’m putting the onsubmit = "checa_formulario()"
However, one of the buttons should perform Submit without entering this function of onsubmit
, but the other button should perform this function.
I tried to call this function on onclick
of the button I want to execute the function, but then it executed the function, but regardless of the result, it performed Submit.
I must use pure javascript.
Could someone help me?
Thanks 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, must enter the function checa_formulario()
.
Already the button with value = 2
, when clicked, should not perform the function checa_formulario()
, but must perform Submit.
I’m calling the function inside the onsubmit
in the form tag, since the two buttons must 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 that’s the job:
if (document.getElementById('descri_icon').value.length < 10) {
alert("Erro");
return (false);
}
This id, descri_icon
is of a textarea
, and the only check is to see if in it, has the minimum of requested characters, but this, if the button with value = 1
is clicked.
Could you explain your question better?
– BrunoVdutra
I’ll edit the code question to explain better
– Gabriel
I edited the question
– Gabriel
I have a question, when one necessarily tightens the other does not have to be activated ever? or can happen of the two?
– BrunoVdutra
Both can even be activated, but the function should only be called with the click on the button with value = 1
– Gabriel
It is a very long form, so the value = 1 button completes the form, and the value = 2 button saves everything that has already been filled in the form but does not complete it... so the value = 2 button does not need validation
– Gabriel
But the value = 2 button still needs Submit because I need the post information to save to a database
– Gabriel
You can disable one button when the other is clicked.. so $('button'). prop('disabled', ! filled);
– BrunoVdutra
https://answall.com/questions/6819/comore-habilitar-um-bot%C3%A3o-only-when-all-the-inputs-are-filled
– BrunoVdutra
Can you tell me how I would do this with javascript? Because I can’t use jquery :/
– Gabriel
Here’s a https://answall.com/questions/22439/howto enable & disable bot%C3%A3o-a-partir-do-onclick-ou-onchange-do-select
– BrunoVdutra