I want to call the variable from the script to body.
Here is my script code. I want to take the rightanswers and wronganswers values to use in html body.
GetFeedback = function (a) {
if (a == CorrectAnswer) {
rightanswers++;
} else {
wronganswers++;
}
lock = true;
}
You need to use the
Document Object Modle. You have different methods with JavaScript to create and insert elements into the DOM. As for example:With that code you are creating an element, then appendig it into the body. And that is pure JavaScript. You could use
MootoolsorjQuery, and It is goign to be simpler. But JavaScript doesn’t work like PHP for example, where you can use the variables mixed up with the HTML.And if you want to trigger the function from the HTML you need to bind thtat function to an event. For example clicking on a link would be.
HTML
JS