I have the following code in HTML which creates a button, that when clicked creates some questions in my page, works fine.
<input type="number" name="quantity" id="num_questions" min="1" max="99"><br>
<input type="button" name="go" id="go_button" value="Go" onclick="createQuestions()"><br>
However, within my function createQuestions()
I have defined a variable in JavaScript, which is based on a number input from my HTML code, shown above.
var number = document.getElementById('num_questions').value;
I have another button which calls a separate function but I need that variable number I locally defined in another function. Is there any way I can grab that variable and use it globally? I tried defining it outside my function, but since the onclick event only calls that one function, it won't create the variable.
Other button:
<input type="submit" name="submit" value="Create Tree" onclick="displayData()">