javascript - Textarea return value is always null -


i trying users input textarea javascript

function validatemessage() {    var message = document.getelementbyid("message").value;    window.alert(message);  }
<label>message:</label>  <textarea rows="5" cols="50" id="message">foo</textarea><button onclick="validatemessage()">validate message</button>

browsers console keeps giving me message

typeerror: document.getelementbyid(...) null[learn more] contact.js:51:14

line 51 actual line in javascript. have read solutions people use .value can see returns null. cannot figure out why.

the error not textarea return value null, getelementbyid null, meaning there's no element id message.

edit: not problem. keeping answer addresses error reason.

"why? have in html". because html bad formatted. have id keyword sitting next closing quotes of 50, without spaces.

change to:

<label>message:</label><textarea rows="5"         cols="50" id="message"></textarea><br/> 

and fine. note space between cols="50" , id="message" now.

as tip, learn understand errors. read them understanding each word.


Comments

Popular posts from this blog

python - Selenium remoteWebDriver (& SauceLabs) Firefox moseMoveTo action exception -

html - How to custom Bootstrap grid height? -

angular - Copying node modules to wwwroot AspNetCore -