SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Zealot maxdream01's Avatar
    Join Date
    Feb 2011
    Location
    USA
    Posts
    149
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    AJAX and HTML5 Validation

    Hi everyone, i have a contact form that i decided to use ajax to submit, i'm validating the data on the server side and i would like to use html5 validation to validate the form on the client side (e.g. <input name="email" type="email" required="required" id="Email" />), however in my ajax JavaScript to initiate the submission i'm using an onclick event on the submit button, however, the html5 validation is initialed on this event as well, so that the submission and validation happens in parallel, thus rendering the validation ineffective. So basically what i want is a way of initiating my ajax submission to occur after the html5 validation.

    Thanks everyone.
    PHP is FUN

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,684
    Mentioned
    99 Post(s)
    Tagged
    4 Thread(s)
    Use setTimeout and return false to prevent the form from being submitted.
    With that setTimeout, set it to something like 100ms so that your delayed function can check the form and then submit it, if appropriate.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  3. #3
    SitePoint Zealot maxdream01's Avatar
    Join Date
    Feb 2011
    Location
    USA
    Posts
    149
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks Paul, but I ended up just using jquery validation, since its more reliable anyway.
    Thanks anyway though.
    PHP is FUN


Tags for this Thread

Bookmarks

Posting Permissions

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