Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

178
Views
JS submit. Validate HTML5 required attribute

I have a HTML5 form with required attributes on my input field. I want to validate the required attribute before i submit the form in the JS. I have made a script but it is not working. Can anyone see my mistake? Currently it is not submiting the data to my php file. If i remove the lines

 var validator = $("#myForm").validate(options);
    if (validator.form()) { ... }

the submit works but the validation is not done. It would submit also emtpy data.

FORM

<form id="myForm" method="post">     
 <input type="week" name="audit_req_date" required>     
 <button type="submit" id="submitFormData" onclick="SubmitFormData();">Submit</button>     
</form>

JS

<script>
    function SubmitFormData() {
        var validator = $("#myForm").validate(options);
        if (validator.form()) {
            // submit with AJAX                                
            var formValues = $('#myForm').serialize();
            $.post("<?= $base ?>beta/assets/ajax/ajax_query.php", formValues,
                function(data) {
                    $('#results').html(data);
                }
            );
        }
    }
</script>

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!