I want to cancel sending the form to the handler until all the fields are filled. In the input is emptiness, but submit still works.

<script type="text/javascript"> $('#send').submit(function(eventObject){ if($('#name').val() == "" || $('#email').val()=='' || $('#date').val()=='') { eventObject.preventDefault(); alert('Вы заполнили не все поля');} }); </script> 

As I noticed, the program does not go inside the function at all.

  • Is jQuery exactly connected? Do you send a form id send button? - Oleg Arkhipov
  • <input name = "send" type = "submit" value = "Go to the time selection" id = "send" class = "btn-send" /> - Radik Kamalov

1 answer 1

Quote from the official manual

This is where the user is attempting to submit a form. It can only be attached to <form> elements.

You need to hang this handler to the form, and you seem to put it on the submit-button.

  • Button submits the same form. How else can the form be hung? - Radik Kamalov
  • For example, set your form id <form id = "mysuperform"> ... </ form> <script type = "text / javascript"> $ ('# mysuperform'). Submit (function (eventObject) {....} ); </ script> - mantigatos
  • It works only when the form has already been passed the parameters. In my case, the geth method. And the first time is not satisfied. How can this be fixed? <form action = "appointments.php" method = "get" class = "reservationForm" id = "reservationForm"> - Radik Kamalov