Onclick respect required field

Asked

Viewed 439 times

0

I created an animation that appears on the screen and blocks the fields entered by the user while the request is processed, directly on submit, as below:

onclick="javascript:document.getElementById('blanket').style.display = 'block';document.getElementById('aguarde').style.display = 'block'; block();"

Appearing the image below:

inserir a descrição da imagem aqui

It turns out that if the user does not fill in some information, the form is not sent and the warning appears due to the required, but the animation runs anyway, and to go back to page only by updating the same.

Is there any way of onClick await validation of the fields required before performing this animation?

1 answer

1

In that case the onclick will be executed anyway. For this lock validation to be activated only if the criteria are met, put in the event onsubmit and take from the onclick. It could be something like:

document.getElementById('meu_form').addEventListener("submit", function(){
    document.getElementById('blanket').style.display = 'block';
    document.getElementById('aguarde').style.display = 'block'; 
    block();
});
  • Thanks for the reply. I changed the function but it did not work, nor called animation.

  • In place of meu_form goes the id of your form. I believe that onlick was on the input type Ubmit, right?! It will only fall into Ubmit if the required ones have been satisfied.

  • Yes, I changed it with my form id, but it didn’t work. I’ll try again.

  • Fine. If you can’t and you can raise a Fiddle, I’ll help you =]

  • 1

    It worked, I put it right into the form event and I took everything from Submit. + 1. Hug and thanks.

  • I just found an "error". It triggers the animation only in the second click of Ubmit. If I fill everything correctly it does not trigger the animation, only if I click first "calling" the error, then after I fill everything it works. There’s something else I need to do?

  • There is no @Diego, without seeing how your HTML is hard to say. Probably for some other reason your code must be generating this behavior.

  • The code is very large, I saved it here if you can take a look: http://200.208.251.153/InsereReserva.txt

  • I’m sorry to ask, but you’ve seen the code?

Show 4 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.