Forum Articles
  Welcome back Join CF
You are here You are here: Home | Forum | Small bit of Javscript help needed...

You are currently viewing our boards as a guest which gives you limited access to view most of the discussions, articles and other free features. By joining our Virgin Media community you will have full access to all discussions, be able to view and post threads, communicate privately with other members (PM), respond to polls, upload your own images/photos, and access many other special features. Registration is fast, simple and absolutely free so please join our community today.


Welcome to Cable Forum
Go Back   Cable Forum > Computers & IT > General IT Discussion

Small bit of Javscript help needed...
Reply
 
Thread Tools
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
Advertisement
Old 23-09-2009, 20:51   #2
Reedy
Inactive
 
Join Date: Jun 2009
Posts: 139
Reedy is just really niceReedy is just really niceReedy is just really niceReedy is just really niceReedy is just really niceReedy is just really nice
Re: Small bit of Javscript help needed...

Get rid of the ' ' like

document.getElementById(textfield).value = yyyy+'-'+mm+'-'+dd;
Reedy is offline   Reply With Quote
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 05:49.


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