Have a textarea tag in form, to take input text and return the value of said text.
<textarea id="code" name="code"></textarea>
Using javascript to get the value, but it returns nothing. Used typeof to check if it's undefined, but typeof text gives 'string'. Is this correct way to use .value? How to improve this?
JavaScript:
var text = document.getElementById('code').value;
document.getElementById('submit-button').onclick = function() {
alert(text);
};