Adding a class to body tag upon validated form submission

Adding a class to body tag upon validated form submission

Hi gang,

I'm working on a little project where they have a slider form and I need to piggyback a tiny line of code into the validation function for the form. 


What I need to happen is when the user has filled in all the fields and clicks the submit button AND the data validates THEN a class is added to the body tag. My jQuery knowledge is very minimal - I added the code to where I 'thought' its supposed to go but it didnt seem to work.


Can someone please point me in the right direction?


  1. jQuery(document).ready(function() {

  2.    jQuery('#scroller').css('overflow','hidden');

  3.    // Set up the scrollable registration
  4.    var wizard = jQuery('#scroller').scrollable();

  5.    // Create the select validator
  6.    jQuery.tools.validator.fn('select[required]', "Please select an option", function(input, value) {
  7.          return (value!=0);
  8.    });

  9.    // Create the password validator
  10.    jQuery.tools.validator.fn('input#password', "Your password is too short. The minimum is 7 characters", function(input, value) {
  11.          return (value.length > 6);
  12.    });

  13.    jQuery.tools.validator.fn('#password_confirm', "Your passwords do not match", function(input, value) {
  14.          return (value == jQuery('#password').val());
  15.    });

  16.    jQuery('.capture_capture_img').click(function(){
  17.       var src = jQuery(this).attr('src');
  18.       var index = src.indexOf('?');
  19.       if(index > 0) {
  20.          src = src.substring(0, index);
  21.       }
  22.       jQuery(this).attr('src', src+'?r='+Math.random());
  23.    });

  24.    var form = jQuery('#newsletter-signup-form form');

  25.    form.validator({
  26.       position: 'top right',
  27.       offset: [5, -10],
  28.       inputEvent: 'blur'
  29.    });

  30.    form.submit(function() {
  31.       // find all the fields inside the current page and validate them

  32.       // Stop the sliding function on validation fail
  33.       if(form.data("validator").checkValidity()) {
  34.          jQuery.ajax({
  35.             type: 'POST',
  36.             url: 'index.php',
  37.             data: 'ajax=1&'+form.serialize(),
  38.             success: function(json) {

  39.                if(json === true) {
  40. // I THOUGHT I COULD ADD THE JQEURY ADDCLASS CODE HERE - BUT IT DIDNT WORK
  41. // $("body").addClass("drop");
  42.                   wizard.scrollable().seekTo(2,undefined,true);
  43.                   sitestat(sitestat_url+'post-register.page')
  44.                } else {
  45.                   form.data("validator").invalidate(json);
  46.                   if(json['capture']) {
  47.                      jQuery('.capture_capture_img').click();
  48.                   }
  49.                }

  50.             },
  51.             dataType: 'json'
  52.          });

  53.          return false;
  54.       }
  55.       return false;
  56.    });


  57. });