Help on jQuery form (going to error stage)

Discussion in 'jQuery' started by lseecon, Dec 19, 2011.

  1. #1
    Hi, my code is below.

    For some reason, upon clicking submit, the code reaches this bit:

    
    error: function(XMLHttpRequest, textStatus, errorThrown) {			alert('Sorry! An error occurred while sending. Please try again later.');
    			$submit.attr('disabled', '');
    Code (markup):
    I am unable to work out why - any help is greatly appreciated as this is driving me crazy!

    Please feel free to let me know if you require any further info.

    Full code:

    
    lse.preregister = function($form) {
    	var $submit = $form.find('input[type="submit"]');
    	var regType = $form.find('select').val();
    	if (regType == 0) {
    		alert('Please choose a registration type!');
    		return;
    	}
    	var pattern = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+[a-zA-Z]{2,4}$/;
    	if (!pattern.test($form.find('input[name="email"]').val())) {
    		alert('Please input a valid e-mail address!');
    		return;
    	}
    	if (!$form.find('input[name="firstname"]').val()) {
    		alert('Please type your first name!');
    		return;
    	}
    	if (!$form.find('input[name="lastname"]').val()) {
    		alert('Please type your last name!');
    		return;
    	}
    	if (!$form.find('input[name="organisation"]').val()) {
    		alert('Please type your university / organisation!');
    		return;
    	}
    	if (!$form.find('input[name="position"]').val()) {
    		alert('Please type your degree level / position!');
    		return;
    	}
    	if (regType % 2 == 0) {
    		if (!$form.find('input[name="course"]').val()) {
    			alert('Please type your course name!');
    			return;
    		}
    		if (!$form.find('input[name="year"]').val()) {
    			alert('Please type your year in university!');
    			return;
    		}
    	}
    	/*$submit.attr('enabled', 'enabled');*/
    	$.ajax({
    		url: $form.attr('action'),
    		type: $form.attr('method'),
    		data: $form.serialize(),
    		dataType: 'json',
    		success: function(data) {
    			if (data.succeed) {
    				window.location.href = './Payment';
    			}
    			else {
    				alert('Sorry! An error occurred while sending. Please verify the form again.');
    				$submit.attr('disabled', '');
    			}
    		},
    		error: function(XMLHttpRequest, textStatus, errorThrown) {
    			alert('Sorry! An error occurred while sending. Please try again later.');
    			$submit.attr('disabled', '');
    		}
    	});
    };
    Code (markup):
     
    lseecon, Dec 19, 2011 IP