Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Senior Coder nikos101's Avatar
    Join Date
    Dec 2006
    Location
    London
    Posts
    1,005
    Thanks
    58
    Thanked 10 Times in 10 Posts

    Question Page submit before the jquery ajax function is called

    in the following code I'm getting a page submit before the function is called from this button click:

    <p >
    <button class="rounded" id="submitB"> Submit</button>
    </p>

    Code:
     $("#submitB").click(function () {
    
    
    
            if (!validateForm()) {
                //failed validation
                return;
            }
    
            $.post("add.cfm", { OrderNumber: $("#OrderNumber").val(),
                LoyaltyNumber: $("#LoyaltyNumber").val()
            },
                function (data) {
                    alert("sdw");
                });
    
    
    
        });


  • #2
    Senior Coder
    Join Date
    Dec 2010
    Posts
    2,387
    Thanks
    11
    Thanked 565 Times in 558 Posts
    A click on a simple button (with no type specified) always triggers a submit (because submit is the default type). If you want to prevent this from happening, you should give the type as "button"
    Code:
    <button class="rounded" id="submitB" type="button"> Submit</button>

  • #3
    Senior Coder nikos101's Avatar
    Join Date
    Dec 2006
    Location
    London
    Posts
    1,005
    Thanks
    58
    Thanked 10 Times in 10 Posts
    cool mate, rep added



  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •