+ 3

Can i make a input field a variable?

I want to set input field as a variable to make a simple calculator.

17th Jul 2019, 4:19 PM
Sabyasachi Pramanik
Sabyasachi Pramanik - avatar
3 Respostas
+ 3
input is html element we can set inside variable and get the value later on. var a = document.getElementById('inputid') var b = a.value
18th Jul 2019, 1:57 AM
Danielov
Danielov - avatar
+ 2
You wouldn't have the input itself as a variable, but you could have your input's value as a variable. Example: ... <body> <input type='text' id='myInput'/> </body> Javascript file: var inputValue= document.getElementById('myInput').value(); Then you could change or do your stuff whenever you click a button or change the input-text etc.
17th Jul 2019, 4:26 PM
Roolin
Roolin - avatar