Is it possible to directly use the result of a Javascript function as an input value for an HTML form?
<form class="my-form" action="fileUpload.php" method="POST" enctype="multipart/form-data">
<input type="hidden" name="User_id" value="getValue();">
<input type="submit" value="Submit"/>
</form>
This is clearly not correct, but I hope it communicates what I am trying to do. I would like the returned result of JS function getValue(); to act as the input value.
In that implementation, no it is not possible to equate the
value
attribute inside theinput
tag to a JavaScript function.According to w3.org, the value attribute can only equal
I am not sure what is inside the
getValue()
function, but you can call a click event handler when the submit button is clicked and run thatgetValue()
function.Ex.
I hope it guides you well.