document.getElementById("ID").value = "TEXT OR VARIABLE";
<input type="text" id="example"> // Setup text field
<script type="text/javascript">
document.getElementById("example").setAttribute('value','My default value');
</script>
<input type="text" id="example">
<input type="submit" value="Submit" onclick="document.getElementById('example').setAttribute('value','My default value')">