These examples ought to point you the right way:-
Code:
<form>
The Date <input type = "text" id = "date"><br>
Quantity 1<input type = "text" id = "qty1"><br>
</form>
<script type = "text/javascript">
window.onload = initForm;
function todayTxt() {
var Today = new Date();
return Today.getMonth()+1+"-"+Today.getDate()+"-"+Today.getFullYear();
}
function initForm() {
document.getElementById("date").value = todayTxt(); // address element by id
document.getElementById("qty1").focus();
}
</script>
Or
Code:
<form>
The Date <input type = "text" name= "date" id = "date"><br>
Quantity 1<input type = "text" name = "qty1" id = "qty1"><br>
</form>
<script type = "text/javascript">
window.onload = initForm;
function todayTxt() {
var Today = new Date();
return Today.getMonth()+1+"-"+Today.getDate()+"-"+Today.getFullYear();
}
function initForm() {
document.forms[0].date.value = todayTxt(); // address element by name
document.forms[0].qty1.focus();
}
</script>
Or, most correctly, assign the id "myform" to the form and then
Code:
function initForm() {
document.getElementById('myform').date.value = todayTxt(); // address form by id, form element by name
document.getElementById("myform").qty1.focus();
}
var document orders // the name of a variable may not contain a space.