I have the following code in HTML which creates a button, that when clicked creates some questions in my page, works fine.
According to How to declare a global variable in a .js file you can define a variable before any function is called and then use it in different functions.
var global1 = "I'm a global!";
function setGlobal () {
global1= document.getElementById('num_questions').value;
}
function testGlobal () {
alert(global1);
}
It is not possible to access a function's local variables from outside of that function, so you have four options:
getElementById()