SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Evangelist silversurfer5150's Avatar
    Join Date
    Aug 2010
    Posts
    534
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Prevent default and then allow again

    Hey there,

    I have an onclick handler which executes and jquery ajax load function but I need to validate a form first before executing the load function. I don't know how to prevent the load from occurring until the validate is complete. I am validating using the jquery validate plugin. Any ideas?

    thanks
    "Persistence is the path to perfection"

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,729
    Mentioned
    104 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by silversurfer5150 View Post
    I don't know how to prevent the load from occurring until the validate is complete. I am validating using the jquery validate plugin. Any ideas?
    The jQuery validate documentation page has a section called "Plugin Methods". At the top of that list of methods is one called "validate( options )" that you can click on to get more details.

    The "validate( options )" page has two tabbed sections, called Overview and Options.

    In the Options tab is one called submitHandler which shows some code to achieve what looks to be precisely what you need.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  3. #3
    SitePoint Evangelist silversurfer5150's Avatar
    Join Date
    Aug 2010
    Posts
    534
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey there,

    Thanks for pointing me in the right direction, got it sorted . I have been working on an opencart mod.

    The fact that a bit cms system like opencart relies on ajax for its checkout funcion showed me that a lot of people aren't considering users with js disabled nowadays and I have always learnt that I should take this into consideration.

    I can see that you're a very experienced js developer, what do you think?
    "Persistence is the path to perfection"

  4. #4
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,729
    Mentioned
    104 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by silversurfer5150 View Post
    I can see that you're a very experienced js developer, what do you think?
    Thanks.

    My belief is that JavaScript should be used to enhance web pages. When scripting is used to supply behaviour that has no alternative means of occurring, that tends to lead to bad places.

    So how a CMS should handle that, is to use standard basic form submissions to do the work, and then to use JavaScript to take over the form submission in order to provide an enhanced user experience, in this case that being to submit using ajax so that a page reload is not needed.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  5. #5
    SitePoint Evangelist silversurfer5150's Avatar
    Join Date
    Aug 2010
    Posts
    534
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question

    Thanks I really appreciate the advice.

    BTW how do you debug your scripts? I have been using firebug and console.log() to dump variables but I would like to learn how to trace through properly, I have tried the Venkman debugger and can't seem to get it to work. Do you know of any good tutorials on tracing though with either Venkman or firebug or anything similar?

    thanks

    Silversurfer
    "Persistence is the path to perfection"

  6. #6
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,729
    Mentioned
    104 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by silversurfer5150 View Post
    BTW how do you debug your scripts?
    I debug them using the built-in debugger that comes with Google Chrome.

    Quote Originally Posted by silversurfer5150 View Post
    I have been using firebug and console.log() to dump variables but I would like to learn how to trace through properly, I have tried the Venkman debugger and can't seem to get it to work. Do you know of any good tutorials on tracing though with either Venkman or firebug or anything similar?
    For basic info about using Firebug with JavaScript, you can start at:
    JavaScript Debugger and Profiler : Firebug
    and
    Script Panel - FirebugWiki

    A tutorial on using it is at:
    Debug JavaScript with Firebug | Code Central

    Typically I breakpoint at a certain place, then use the step commands to walk on through the execution to help narrow down the cause.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  7. #7
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,868
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by paul_wilkins View Post
    I debug them using the built-in debugger that comes with Google Chrome.
    That one is just about identical in how it works to the Venkmann extension for Firefox (and also as similar to the ones built into Safari, IE8, and Opera).

    About the only difference between them all is where you find the option to open them.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  8. #8
    SitePoint Evangelist silversurfer5150's Avatar
    Join Date
    Aug 2010
    Posts
    534
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question

    Thanks for the advice both,

    My javascript is getting better than my ability to guess what outcome I will get from it so I must learn asap to debug properly!
    "Persistence is the path to perfection"


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
  •