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开发者_JS百科 know.
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;
document.getElementById('element-id').value = 'The Value';
Value="<script type="text/javascript">document.write(yourVariableName);</script>"
You can do just:
document.getElementById('inputId').value = yourVariable;
You can also use the jQuery library, it will:
$('#inputId').val(yourVariable);
- jQuery : http://jquery.com/
- function .val: http://api.jquery.com/val/
精彩评论