How to transfer the value of input to the variable js | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

How to transfer the value of input to the variable js

I'm just starting to learn the course of js through SoloLearn and having reached logical operations I wanted to write a simple program that compares the value of <input> with the value of the variable js. I will be very grateful for the answer!)

8th Sep 2018, 7:16 AM
ANOD
ANOD - avatar
3 Answers
+ 5
<input type='text' id='demo' value="Hello Guy!" /> <script> var inputData = document.getElementById("demo").value; alert(inputData); </script>
8th Sep 2018, 10:14 AM
Googel
Googel - avatar
+ 2
You can get the value of an input using this: var whatYouWant = document.getElementById("...").value where ... is the id of input element. So the rest is: if(whatYouWant == otherVar) {...}
8th Sep 2018, 7:36 AM
Ledio Deda
Ledio Deda - avatar
+ 1
var variable = document.write[form][name].value;
8th Sep 2018, 11:49 AM
CHINNEM SUNIL KUMAR
CHINNEM SUNIL KUMAR - avatar