Reputation: 149
How do you put a javascript variable into the value=""
of an <input>
box on a <form>
This must be easy but I do not know.
Upvotes: -1
Views: 104
Reputation: 21844
You can do just:
document.getElementById('inputId').value = yourVariable;
You can also use the jQuery library, it will:
$('#inputId').val(yourVariable);
Upvotes: 0
Reputation: 392
Value="<script type="text/javascript">document.write(yourVariableName);</script>"
Upvotes: 0
Reputation: 349002
That's not hard. Have a look at the example below:
HTML:
<input id="id_of_your_element">
Javascript:
var yourvariable = "Hello world!";
document.getElementById("id_of_your_element").value = yourvariable;
Upvotes: 1