Cable Forum

Cable Forum (https://www.cableforum.uk/board/index.php)
-   General IT Discussion (https://www.cableforum.uk/board/forumdisplay.php?f=19)
-   -   Small bit of Javscript help needed... (https://www.cableforum.uk/board/showthread.php?t=33655746)

Druchii 23-09-2009 20:27

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 :o:

Reedy 23-09-2009 20:51

Re: Small bit of Javscript help needed...
 
Get rid of the ' ' like

document.getElementById(textfield).value = yyyy+'-'+mm+'-'+dd;


All times are GMT +1. The time now is 07:29.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
All Posts and Content are © Cable Forum