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
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
+ 4
https://www.tabnine.com/academy/javascript/get-value-of-input/
Hope it's helpful to you
+ 3
document.querySelect("#input-Id").value.
+ 3
Didnt work sorry
+ 2
Jamescabc
onload => login();
Name.value;
+ 2
Thank you for your support
+ 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);
}
0
Jamescabc
here's a simpler example
https://code.sololearn.com/WBde556Ud90J/?ref=app