Wednesday 15 June 2011

javascript - How to activate a function if an action has completed a set number of times? -



javascript - How to activate a function if an action has completed a set number of times? -

below script allows user move forwards , through questions. if user comes lastly question , clicks next button want page go finished.html. on first click programme brings user this.

var actual = 0; // select default first question $(document).ready(function() { var number_of_question = $('.question').length; // number of questions $('.question:gt(' + actual + ')').hide(); // hide unselect question $('#nextq').click(function() { if (actual < number_of_question - 1) { changequestion(actual + 1); // display select question } if (actual = number_of_question) { //alert("finished"); window.location.href = 'finished.html'; } }); $('#previousq').click(function() { if (actual) { changequestion(actual - 1); // display select question } }); }); function changequestion(newquestion) { $('.question:eq(' + actual + ')').hide(); // hide current question $('.question:eq(' + newquestion + ')').show(); // show new question actual = newquestion; // memorize actual selection $('#question_number').html(actual); }

you need actual === number_of_question, right assigning value actual

javascript

No comments:

Post a Comment