0

Hey everyone, am trying to get the user value from an input box and store the value in a variable.

But whenever I use the ".value" property it is giving me an error saying I can't set the value of null so what could be the problem and solution to this problem thank you in advance.

7th Jan 2020, 12:10 PM
Tizlan
Tizlan - avatar
3 Antworten
+ 4
The js code in SL play ground is embed in the <head> </head> tag by default. At this time (when your js code loading) your html element use to store user's input still not created yet and that cause the error. So you need to wrap your js code like this: window.onload = function(){ Your code goes here }
7th Jan 2020, 12:37 PM
Thống Nguyễn
Thống Nguyễn - avatar
+ 3
Can you show us your code here?
7th Jan 2020, 12:15 PM
Yaroslav Vernigora
Yaroslav Vernigora - avatar
0
// variables for greeting text code var chatbot = document.querySelector('.chatbot'); var reply = document.querySelector('.reply'); var response_bot = document.querySelector('.response_bot'); var send_button = document.querySelector('.send_button'); var input = document.querySelector('#input').value; // fuction for greeting text code function hello() { if(isNaN(input) || input < 1 || input > 10) { alert("how are you " + input ); return false; } }
7th Jan 2020, 12:46 PM
Tizlan
Tizlan - avatar