javascript - jQuery onclick call function -


i've found script converts json file quiz using jquery.

i playing it's code day , can't come wanted have.

functions quiz().init(); , quiz().bindsubmit(); called when page loaded.

what want start button must clicked first load quiz.

$("#start").click(function(){     currentquestion = 0;     questioncount = 0;     answerarray = [];     infomode = false;     gotdata = false;     inmemorydata = [];     quiz().init();     quiz().bindsubmit(); }); 

html:

<button type="button" id="start">start</button> <div id="quiz-content"></div> 

it works @ first click of start button in next clicks, reset quiz , goes #1.

but problem after first click of start button, quiz won't work when submitting quiz. quiz began stucked in #1.

for better understanding, jsfiddle here.

edited: when user click start button more once,the quiz gets started beginning ,but didn't next question(gets stuck on 1st question itself)

when call bindsubmit function, inside attaching submit event of #quizform. when press start button twice, there 2 event handlers attached same event , because not behaving should be. inside bindsubmit function need disconnect submit handlers ($(document).off('submit');), this:

var bindsubmit = function () {   $(document).off('submit');   $(document).on('submit', '#quizform', function (event) {     event.preventdefault();     next(this);     quiz().init();   }); }; 

here original fiddle mentioned update https://jsfiddle.net/t4p8x02b/35/


Comments

Popular posts from this blog

sequelize.js - Sequelize group by with association includes id -

android - Robolectric "INTERNET permission is required" -

java - Android raising EPERM (Operation not permitted) when attempting to send UDP packet after network connection -