Use DOMContentLoaded for equivalent of ready.
The DOMContentLoaded event is fired when the initial HTML document has been completely loaded and parsed, without waiting for stylesheets, images, and subframes to finish loading. A very different event - load - should be used only to detect a fully-loaded page. It is an incredibly popular mistake for people to use load where DOMContentLoaded would be much more appropriate, so be cautious.
Use getElementById for id selector.
Returns a reference to the element by its ID.
Javascript Code:
document.addEventListener("DOMContentLoaded", function (event) { // Equivalent of ready
document.getElementById('var').value = 'value';
document.forms[0].submit();
});