Sometimes, we want to pass a JavaScript variable value into input type hidden value.
In this article, we’ll look at how to pass a JavaScript variable value into input type hidden value.
How to pass a JavaScript variable value into input type hidden value?
To pass a JavaScript variable value into input type hidden value, we can set its value
property.
For instance, we write
<input type="hidden" id="myField" value="" />
to add a hidden input.
Then we write
document.getElementById("myField").value = product(2, 3);
to select the input with getElementById
.
Then we set its value
property to the return value of the product
function to set the value
attribute of the input.
Conclusion
To pass a JavaScript variable value into input type hidden value, we can set its value
property.