+ 3
Can i make a input field a variable?
I want to set input field as a variable to make a simple calculator.
3 Antworten
+ 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
+ 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.