View Single Post
Old 23-09-2009, 20:27   #1
Druchii
cf.mega poster
 
Druchii's Avatar
 
Join Date: Mar 2006
Location: Oslo, Norway.
Age: 36
Services: Canal Digital: 50/10
Posts: 7,577
Druchii has a nice shiny star
Druchii has a nice shiny starDruchii has a nice shiny starDruchii has a nice shiny starDruchii has a nice shiny starDruchii has a nice shiny starDruchii has a nice shiny starDruchii has a nice shiny starDruchii has a nice shiny starDruchii has a nice shiny starDruchii has a nice shiny starDruchii has a nice shiny starDruchii has a nice shiny starDruchii has a nice shiny starDruchii has a nice shiny starDruchii has a nice shiny starDruchii has a nice shiny starDruchii has a nice shiny starDruchii has a nice shiny star
Small bit of Javscript help needed...

Hey, I'm trying to populate one textbox with todays date formatted as YYYY-MM-DD.

So far, i have the following Javascript that seems not to work correctly:
Code:
<script type="text/javascript">
function DateContent()
{
var today = new Date();
var dd = today.getDate();
var mm = today.getMonth()+1;//January is 0!
var yyyy = today.getFullYear();
if(dd<10){dd='0'+dd}
if(mm<10){mm='0'+mm}
document.getElementById('textfield').value = yyyy+'-'+mm+'-'+dd;
}
</script>
The textbox is degined as "name="textfield"" in the HTML.
The <body> tag includes OnLoad=DateContent() to make the function fire also.
I know the function to get the date works, but, getting it to populate the textbox fails.

Any ideas?

---------- Post added at 20:18 ---------- Previous post was at 19:37 ----------

C'mon, anyone?

Any other solution would work too, so, if you don't know what's wrong, but have a suggestion, let me know!

---------- Post added at 20:27 ---------- Previous post was at 20:18 ----------

God i'm a dipstick, needed to add id=textfield to the actual text field
Druchii is offline   Reply With Quote