function formv3 (){ // Get form fields var formFields = []; $('.result_form .hs-form-field input[type="hidden"]').each(function(){ formFields.push($(this).attr('name')); }); // Get results var results = []; function questionResults() { $('.slick-slide .custom-radio.active .custom-control-label').each(function(){ var resultText = $(this).text(); results.push(resultText); }); overallResult(); } function overallResult () { results.push($('.result_text.active .better').text().trim()); } questionResults(); for(i=0; i < formFields.length; i++) { $('.result_form .hs-form-field input[name="'+formFields[i]+'"]').val(results[i]).change(); } } $(window).load(function() { $("#full_wrapper").addClass("disble"); $("#full_wrapper .slick-active input").on("change",function(){ $("#full_wrapper").removeClass("disble"); }) }); $("#airthingQuiz").validate({ ignore: '', rules: { stp1: "required", stp2: "required", stp3: "required", stp4: "required", stp5: "required", stp6: "required", stp7: "required", stp8: "required", stp9: "required", stp10: "required" }, messages: { stp1: "Please select an answer", stp2: "Please select an answer", stp3: "Please select an answer", stp4: "Please select an answer", stp5: "Please select an answer", stp6: "Please select an answer", stp7: "Please select an answer", stp8: "Please select an answer", stp9: "Please select an answer", stp10: "Please select an answer" }, errorPlacement: function(error, element) { error.appendTo(element.parent(".custom-control").siblings(".errorBlock")) } }) $(document).ready(function() { var $slideshowId = $('.quiz-module .slick-carousel').attr("id"); var $slideshowContainer = $('#'+$slideshowId); function createSlick(){ $slideshowContainer.not('.slick-initialized').slick({ arrows: false, centerPadding: "0px", dots: false, slidesToShow: 1, infinite: false, draggable:false, swipeToSlide:false, swipe:false }); } createSlick(); $('.quiz-module .next').click(function(e) { e.preventDefault(); // if(!$("#full_wrapper").hasClass("disble") && $(".slick-slide.slick-current input").valid()){ if($(".slick-slide.slick-current input").valid()){ setTimeout(function(){ $slideshowContainer.slick('slickNext'); }, 1000) $(".score_card .true").html($(".custom-control.true.active").length) $("#full_wrapper").addClass("disble"); } }); $slideshowContainer.on('beforeChange', function(event, slick, currentSlide, nextSlide){ $(".slick-slide[data-slick-index="+currentSlide+"] .details").css('display','none'); }); $slideshowContainer.on('afterChange', function(event, slick, currentSlide, nextSlide){ $(window).on( 'resize', createSlick ); if($("#full_wrapper").hasClass("disble")){ // $('.slick-carousel').slickSetOption(null, null, true); $(".next").on("click",function(){ return false; }) } $("#full_wrapper .slick-active input").on("change",function(){ $("#full_wrapper").removeClass("disble"); }) $(".next").attr("id", "next_"+(currentSlide+1)) $(".page").html(currentSlide+1) if(currentSlide+1 =="10"){ $("body").addClass("show_btn") } if(currentSlide+1 =="11"){ $("body").addClass("final_result") } }); /***functionality***/ $(".custom-control input").on("click",function(){ $(this).parent().parent().addClass("disble") $(this).parent().siblings().removeClass("active true false") var a=($(this).attr("name")) if($(this).val()){ $(this).parents('.slide-content').find('.error_msg').css('display', 'none') } if($(this).val()=='true'){ $(this).parent().addClass("active true"); }else{ $(this).parent().parent().find("input").each(function(){ if($(this).val()=='true'){ console.log($(this).parent().addClass("true")) } }) $(this).parent().addClass("active false"); $(this).parents(".slide-content").find(".details").addClass("error_details") } }) $(".result").on("click",function(){ if(!$("#full_wrapper").hasClass("disble")){ $(".result_page").addClass("done"); $('.slick-carousel').slick('slickGoTo', 11); var res=parseInt($(".custom-control.true.active").length); // $(".result_text").removeClass("active") var desc = encodeURIComponent(document.querySelector('meta[name="description"]').content); var image = "https://www.airthings.com/hs-fs/hubfs/Quiz-Header%20(2).png" if(res>=0 && res<5){ $(".be_better").addClass("active"); $(".facebookSend").attr("href","http://www.facebook.com/dialog/feed?app_id=511465846169863&link="+ window.location.href.split('?')[0] +"&picture="+ image +""e=My%20indoor%20air%20could%20be%20better%2C%20take%20the%20quiz%20and%20find%20out%20yours%20now&caption="+ desc +"&redirect_uri="+window.location.href.split('?')[0]); $(".twitterSend").attr("href","https://twitter.com/intent/tweet?text=My+indoor+air+could+be+better%2C+take+the+quiz+and+find+out+yours+now&url="+window.location.href.split('?')[0]); }else if(res>=5 && res<9){ $(".Not_bad").addClass("active"); $(".facebookSend").attr("href","http://www.facebook.com/dialog/feed?app_id=511465846169863&link="+ window.location.href.split('?')[0] +"&picture="+ image +""e=My%20indoor%20air%20is%20not%20bad%2C%20take%20the%20quiz%20and%20find%20out%20yours%20now&caption="+ desc +"&redirect_uri="+window.location.href.split('?')[0]); $(".twitterSend").attr("href","https://twitter.com/intent/tweet?text=My+indoor+air+is+not+bad%2C+take+the+quiz+and+find+out+yours+now&url="+window.location.href.split('?')[0]); }else if(res>=9 && res<11){ $(".Excellent").addClass("active"); $(".facebookSend").attr("href","http://www.facebook.com/dialog/feed?app_id=511465846169863&link="+ window.location.href.split('?')[0] +"&picture="+ image +""e=My%20indoor%20air%20is%20excellent%2C%20take%20the%20quiz%20and%20find%20out%20yours%20now&caption="+ desc +"&redirect_uri="+window.location.href.split('?')[0]); $(".twitterSend").attr("href","https://twitter.com/intent/tweet?text=My+indoor+air+is+excellent%2C+take+the+quiz+and+find+out+yours+now&url="+window.location.href.split('?')[0]); } } formv3(); }) });