function isValidEmailAddress(emailAddress) { var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i); return pattern.test(emailAddress); } $(document).ready(function () { //if submit button is clicked $('#submit').click(function () { //Get the data from all the fields var subjectList = $('#subjectList'); var feedbackTypeList = $('#feedbackTypeList'); var name = $('input[name=name]'); var email = $('input[name=email]'); var comments = $('textarea[name=comments]'); var aff = $('input[name=aff]'); var errorInform = false; $('.emailError').hide(); //Simple validation to make sure user entered something //If error found, add highlight class to the text field if (subjectList.val() == '') { subjectList.addClass('highlight'); errorInform = true; } else subjectList.removeClass('highlight'); if (feedbackTypeList.val() == '') { feedbackTypeList.addClass('highlight'); errorInform = true; } else feedbackTypeList.removeClass('highlight'); if (name.val() == '') { name.addClass('highlight'); errorInform = true; } else name.removeClass('highlight'); if (!isValidEmailAddress(email.val())) { // if (email.val()=='') { email.addClass('highlight'); $('#contact_form .email').addClass('error'); $('.emailError').show(); errorInform = true; } else email.removeClass('highlight'); $('#contact_form .email').removeClass('error'); if (comments.val() == '') { comments.addClass('highlight'); errorInform = true; } else comments.removeClass('highlight'); if (errorInform == true) { $('.failure').fadeIn('slow'); return false; } //organize the data properly var data = 'aff=' + aff.val() + '&feedbackTypeList=' + feedbackTypeList.val() + '&subjectList=' + subjectList.val() + '&name=' + name.val() + '&email=' + email.val() + '&comments=' + encodeURIComponent(comments.val()); //disabled all the text fields $('.text').attr('disabled', 'true'); //show the loading sign $('.loading').show(); //start the ajax $.ajax({ //this is the php file that processes the data and send mail url: "http://newsvine.msnbc.msn.com/_nv/api/cms/info/contact", //http://www.newsvine.com/_nv/api/cms/info/contact", //GET method is used type: "GET", //pass the data data: data, //Do not cache the page cache: false, //datatype dataType: "jsonp", //success success: function (data) { // console.log('Got response'); //if successful if (data.statusCode == "success") { //hide the form // $('#contact_form').hide(); $('#contact_form .email').removeClass('error'); $('#contact_form input, #contact_form textarea, #contact_form select').attr('disabled', 'true'); //show the success message $('.success').fadeIn('slow'); $('.failure').hide(); //if newsvine failure } else { $('.delivery').fadeIn('slow'); } //else alert('Sorry, unexpected error. Please try again later.'); } }); //cancel the submit button default behaviours return false; }); });