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?
- jQuery(document).ready(function() {
- jQuery('#scroller').css('overflow','hidden');
- // Set up the scrollable registration
- var wizard = jQuery('#scroller').scrollable();
- // Create the select validator
- jQuery.tools.validator.fn('select[required]', "Please select an option", function(input, value) {
- return (value!=0);
- });
- // Create the password validator
- jQuery.tools.validator.fn('input#password', "Your password is too short. The minimum is 7 characters", function(input, value) {
- return (value.length > 6);
- });
- jQuery.tools.validator.fn('#password_confirm', "Your passwords do not match", function(input, value) {
- return (value == jQuery('#password').val());
- });
- jQuery('.capture_capture_img').click(function(){
- var src = jQuery(this).attr('src');
- var index = src.indexOf('?');
- if(index > 0) {
- src = src.substring(0, index);
- }
- jQuery(this).attr('src', src+'?r='+Math.random());
- });
- var form = jQuery('#newsletter-signup-form form');
- form.validator({
- position: 'top right',
- offset: [5, -10],
- inputEvent: 'blur'
- });
- form.submit(function() {
- // find all the fields inside the current page and validate them
- // Stop the sliding function on validation fail
- if(form.data("validator").checkValidity()) {
- jQuery.ajax({
- type: 'POST',
- url: 'index.php',
- data: 'ajax=1&'+form.serialize(),
- success: function(json) {
- if(json === true) {
- // I THOUGHT I COULD ADD THE JQEURY ADDCLASS CODE HERE - BUT IT DIDNT WORK
- // $("body").addClass("drop");
-
- wizard.scrollable().seekTo(2,undefined,true);
- sitestat(sitestat_url+'post-register.page')
- } else {
- form.data("validator").invalidate(json);
- if(json['capture']) {
- jQuery('.capture_capture_img').click();
- }
- }
- },
- dataType: 'json'
- });
- return false;
- }
- return false;
- });
- });