$(document).ready(function() { $('.QuestionOption').bind('mousedown',function() { var par = $(this).parent('.QuestionText'); var childs = $(par).find('.QuestionOption').removeClass('selected'); $(this).addClass('selected'); NextPage($(this).attr('rel')); }); $('.NextQuestion').click(function() { NextPage(); }); $('.PreviousQuestion').click(function() { if ($(this).hasClass('GoToFirst')) { $('.QuizAnswer').hide(); PreviousQuestion(1); } else { PreviousQuestion($(this).attr('rel')); } }); }); function NextPage(ID) { var Old = $('#Question-'+ID); $(Old).hide(); ID++; var Next = $('#Question-'+ID); //console.log($(Next)); if ($(Next).hasClass('QuizAnswer')) { ShowAnswers(); } $(Next).fadeIn(); } function PreviousQuestion(ID) { var Old = $('#Question-'+ID); $(Old).hide(); ID--; var Next = $('#Question-'+ID); $(Next).fadeIn(); } function ShowAnswers() { //var answers = $('.QuestionOption.selected'); //var arr = $.makeArray(answers).serializeArray(); //console.log(arr.serialize()); var vals = $('#ShowQuiz').find('.selected').toArray(); var answers = []; for (var i = 0; i < vals.length; i++) { answers.push(vals[i].getAttribute('id')); } //console.log($('#ShowQuiz').find('.selected')); //console.log(answers); $.ajax({ type: 'POST', url: 'https://www.hearthgrounded.com/Components/Quiz/Assets/AJAX/ShowAnswers.php?id=1', dataType : 'text', // data type data : {answers:answers}, success: function(msg){ var ret = msg.split(':;:'); $('#QuestionAnswer').html(ret[1]); } }); }