First of all, I have been looking around previous answers and altering my code however none of the solutions I have previously read have worked for me. Basically I have all my questions and answers saved in a jStorage and I am trying to create a review page, where the question and the answer are posted, as well as a new button that links the user back to the page where the answered the question.
I use two functions, the createReviewPage() which creates the page for the user, showing the question and the answer. Also I have the reviewPageButton(int).
Basically I need to attach the reviewPageButton() function to newly created buttons and I have been trying to use on.('click') to find the button to the function when it is created, however the event is firing before I even click a button.
My first function (Note some of my previous attempts have been commented out):
function createReviewPage() {
var questions = [];
for (var index = 1; index < 5; index++) {
questions.push($.jStorage.get("question" + index));
}
for (var index = 0; index < questions.length; index++) {
console.log(questions[index].questionText);
$('#resultDisplay').append("<h2> You answered " + questions[index].chosenAnswer + " to the question " + questions[index].questionText + "</h2>");
$('#resultDisplay').append("<input type = 'button' id = 'qbutton" + (index + 1) + "'/>");
// $('.qbutton' + (index + 1)).on("click", '#qbutton' + (index+1), invokeButton(index));
// $('body').on('click', '.qbutton'+(index+1),reviewPageButton(index));
$('.qbutton'+(index+1)).on('click',reviewPageButton(index));
$('#resultDisplay').append("<br> <br> <br>");
}
}
And my reviewPageButton()
function reviewPageButton(number) {
var currentquestion = $.jStorage.get("question" + (number + 1));
currentquestion.reviewed = "Yes";
$.jStorage.set("question" + (number + 1), currentquestion);
window.open("../src/questionpage" + (number + 1) + ".php", "_self");
}