Reputation: 3
(Homework help)
I've tried every little combination and error checking that I can think of, and I still feel stupid being stumped with this one issue. In my HTML, I have an onCLick event for a form that once a user clicks anywhere on the form, the date is supposed to show up in a textbox at the top right of the screen. I can't seem to get my JS to work exactly how I need it to though. I can make it show me the correct value with alerts or document.write's, but it won't populate the text box. Help?
/*function to get today's date */
function today()
{
var today = new Date();
var month = today.getMonth() + 1;
var day = today.getDate();
var year = today.getFullYear();
if(day<10)
{
day= '0' + day;
}
if(month < 10)
{
month = '0' + month;
}
today = month + '/' + day + '/' + year;
return today;
}
/*function to get date to load on startup */
function startform()
{
document.getElementById("formdate").value = today();
}
And my HTML snippet for that form:
<form name="paycheck" onclick="startform()">
I have the JS and HTML files linked up because like I said, I can get the date to show other ways, just not the one I'm trying to get.
EDIT: The input box is as follows:
<input class="date" name="formdate" size="10">
Upvotes: 0
Views: 4233
Reputation: 54
You just missed the id attribute of your textbox:
id="formdate"
Upvotes: 0
Reputation: 224
When selecting via id:
document.getElementById("formdate")
Just make sure to have an id assigned to the element:
<input class="date" name="formdate" id="formdate" size="10">
probably just an oversight
Upvotes: 1