In javascript you can find your element in various ways. document.getElementById is a function that (like the name suggests) finds your html element by the id attribute. In javascript you can set the value of your html element like this:
test.html
<input type="text" id="my_var" value="">
test.js
var test = "hello world";
document.getElementById('my_var').value = test;
I can also recommend jQuery if you want to do more html-element manipulations. jQuery is very easy if you know a little CSS, you can select element with the same way, with jQuery you can manipulate the HTML instead of the style. It would look something like this:
test.html
<script src="path-to/jquery.js"></script>
<script src="path-to/test.js"></script>
....
<input type="text" id="my_var" value="">
test.js
var test = "hello world";
jQuery('#my_var').val( test );