Jquery form validation not working?

JulianJ

I hope someone can help me with some jquery script that I have been building up over a while. The script works and posts some form data to a mysql database successfully.

The problem I have is I'm trying to implement form validation but I cannot get the validation to work and I suspect that I am placing a bracket incorrectly somewhere. The script I post here works but the form validation doesn't. Any help greatly appreciated.

$(document).ready(function() {
$("#your_results").hide();
$("#your_data").hide();
$("#submitButtonId").on("click", function(e) {
    $('#gauge').empty();
    e.preventDefault();

    //Validate the input

    $(function() {
        $("#myform").validate({
});

        //Post the form if field has been completed

        var formdata = $('#myform').serialize();
        $.post('php_includes/insert.php', formdata,
            function(data) {

                //Reset Form

                $('#myform')[0].reset();
                fetchRowCount();
            });

        return false;
    });
});

//Fetch data from server

function fetchRowCount() {
    $.ajax({
        url: 'php_includes/server.php',
        dataType: "json",
        success: function(data) {
            $("#rows").html(data.rows);
            $("#min").html(data.min);
            $("#max").html(data.max);
            $("#mean").html(data.total);
            $("#last").html(data.last_entry);

            //Show gauge once json is received from server

            var gage = new JustGage({
                id: "gauge",
                value: data.total,
                min: data.min,
                max: data.max,
                title: "Sample Data"


            });
            $("#your_results").fadeIn("slow");
            $("#your_data").fadeIn("slow");
            //Scroll to Gauge
            $('html, body').animate({
                scrollTop: $('#results').offset().top
            }, 'slow');
            $("#gauge").fadeIn(slow);

        }

             });
               }
            });

myform

<form class="form-inline" action="" id="myform" form="" method="post">

            <!-- Text input-->
            <div class="form-group">
                <label class="col-md-4 control-label" for="bill_cost"></label>
                <div class="col-md-8">
                    <input id="bill_cost" name="bill_cost" type="text" placeholder="Bill Cost" class="form-control input-lg">

                </div>
            </div>
 <!-- Button -->
            <div class="form-group">
                <label class="col-md-4 control-label" for="submit1"></label>
                <div class="col-md-4">
                    <input type="submit" id="submitButtonId" name="submit1" class="btn btn-primary btn-xl" value="Submit">


                </div>
            </div>
</form>

Results displayed here

<div class="container">
            <div class="row">
                <div class="col-lg-12 text-center">
 <!-- RESULTS HERE -->
<div id="your_results"></div>
 <!-- .GAUGE HERE -->
<div id="gauge" class="300x260px"></div>
Angel Joseph Piscola

If you properly indent your code the problem would become apparent:

$(function() {
    $("#myform").validate({});

    //Post the form if field has been completed

    var formdata = $('#myform').serialize();
    $.post('php_includes/insert.php', formdata,
        function(data) {

            //Reset Form

            $('#myform')[0].reset();
            fetchRowCount();
        });

    return false;
});

You are wrapping your validate function in a $(handler) (A JQuery object, when passed a function, becomes shorthand for $(document).ready(handler);. So you're running your validation on document ready and not when you click your submit button.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

jQuery validation not working with that form

From Dev

Jquery: Form validation not working

From Dev

Jquery form validation not working?

From Dev

jQuery validation on form not working

From Dev

jQuery validation not working with that form

From Dev

Form validation not working in jQuery

From Dev

jQuery form validation not working with bootstrap

From Dev

Form validation with Jquery not working with Chrome

From Dev

Form validation with Jquery not working with Chrome

From Dev

jQuery form validation not working with bootstrap

From Dev

jQuery validation is not working in contact form

From Dev

Jquery form validation is not working properly

From Dev

jQuery Validation From Dynamic Form Not Working

From Dev

Jquery form validation submit handler not working

From Dev

Ajax form submission with Jquery validation plugin is not working

From Dev

jQuery form validation default message replace not working

From Dev

jQuery Form Validation simple example not working

From Dev

jquery.steps and validation not working - form content not visible (invisible)

From Dev

jquery ajax form validation not working with GET method codeigniter

From Dev

ASP MVC jQuery validation onfocusout working, but not on form submit

From Dev

Form not submitting and jQuery validation not working unless submit button is clicked twice

From Dev

Form validation with JS not working

From Dev

Validation Form is not working

From Dev

Angular form validation is not working

From Dev

form validation not working as intended

From Dev

Validation not working on form

From Dev

CakePHP Form Validation Not Working

From Dev

form validation not working in angular

From Dev

Javascript form validation not working

Related Related

HotTag

Archive