Input? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Input?

How do I get a HTML input into a JavaScript variable https://code.sololearn.com/WJ3cBjFR7yjh/?ref=app In the comments is the question

17th Jun 2023, 10:30 AM
Jamescabc
Jamescabc - avatar
8 Answers
+ 2
Jamescabc It didn't work because the HTML tab and the JS tab in your code are not linked properly in the way Sololearn app requires them to be. Here is the fix. I took a shortcut by accessing the Ids directly in the javascript tab without first using querySelectors and assigning to variables. Js have direct access to DOM ids. The main point is input.value is how you get the input value. The input values are displayed in an alert box for this example. One common problem in Sololearn is mixing HTMLcallback assignment and Javascript Tab function definitions. My suggestion is to assign all callbacks in the js tab and not to use the onclick on the HTML tags. https://code.sololearn.com/Wcqf1eNMSQfb/?ref=app
17th Jun 2023, 1:10 PM
Bob_Li
Bob_Li - avatar
+ 4
https://www.tabnine.com/academy/javascript/get-value-of-input/ Hope it's helpful to you
17th Jun 2023, 12:22 PM
Sakshi
Sakshi - avatar
+ 3
document.querySelect("#input-Id").value.
17th Jun 2023, 10:49 AM
Bob_Li
Bob_Li - avatar
+ 3
Didnt work sorry
17th Jun 2023, 11:05 AM
Jamescabc
Jamescabc - avatar
+ 2
Jamescabc onload => login(); Name.value;
17th Jun 2023, 11:24 AM
Solo
Solo - avatar
+ 2
Thank you for your support
17th Jun 2023, 5:07 PM
Jamescabc
Jamescabc - avatar
+ 2
HTML Part : <input type="text" id="myInput" value="Hello, World!"> <button onclick="myFunction()">Click me</button> JS Part: function myFunction() { var inputValue = document.getElementById("myInput").value; console.log(inputValue); }
18th Jun 2023, 8:59 AM
Vaibhav
Vaibhav - avatar
17th Jun 2023, 4:02 PM
Bob_Li
Bob_Li - avatar