To show a hidden div with If-else condition for mobile quiz application -
what want do:
trying create mobile quiz application display list of questions in form 1 one.
what able do:
have read through site , able scroll through questions without problems. also, javascript scoring engine working fine.
<script type="text/javascript"> $(document).ready(function () { var currentquestion=0; var totalquestions=$('questions').size(); $questions = $('.questions'); $questions.hide(); $('.scorepage').hide(); $($questions.get(currentquestion)).fadein(); //show first question // when users click on "next question button... $('#next').click(function(){ $($questions.get(currentquestion)).fadeout(function(){ //hide current question currentquestion = currentquestion + 1; //go next question if(currentquestion == totalquestions){ //if no more question $('.scorepage').show(); $('.button1').hide(); }else{ $($questions.get(currentquestion)).show(); //else display current question } }); }); }); </script> what current program structure:
the application begins form of n questions. each question framed using <div data-role="fieldcontain" class="questions"> questions radio button inputs </div>.
following question, there button, in clicking on call getscore() javascript. section framed <div class="scorepage"> button here , textbox display score</div>.
finally, navigation button @ end of form. framed <div class ="button1"></div>
what problem?
before answering question, scorepage hidden. achieved $('.scorepage').hide();. however, not show scorepage when there no more question using $('.scorepage').show(); , hide next button (since there no more question) using $('.button1').hide();
can see mistake in logic is?
to count number of questions, try using jquery function lenght counting elements:
var totalquestions = $('.questions').length his should work
Comments
Post a Comment