Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Aug 8th, 2005, 8:34 PM   #1
dereko04011
Newbie
 
Join Date: Jan 2005
Posts: 9
Rep Power: 0 dereko04011 is on a distinguished road
Todays Date Problem

Ok for my website I'm trying to do a simple todays date box. and I need it to be like this:
<script type="text/javascript">
adate = new Date()
var badaydate = adate.getDay()
var numdate = adate.getDate()
var bamonthdate = adate.getMonth()
var yeardate = adate.getFullYear()
if (badate == 1) {
var daydate = Monday;
}
if (badate==0) {
var daydate = Sunday;
}
if (badate==2) {
var daydate = Tuesday;
}
if (badate==3) {
var daydate = Wednesday;
}
if (badate==4) {
var daydate = Thursday;
}
if (badate==5) {
var daydate = Friday;
}
if (badate==6) {
var daydate = Saturday;
}
if (bamonth==0) {
var monthdate = January;
}
if (bamonth==1) {
var monthdate = February;
}
if (bamonth==2) {
var monthdate = March;
}
if (bamonth==3) {
var monthdate = April;
}
if (bamonth==4) {
var monthdate = May;
}
if (bamonth==5) {
var monthdate = June;
}
if (bamonth==6) {
var monthdate = July;
}
if (bamonth==7) {
var monthdate = August;
}
if (bamonth==8) {
var monthdate = September;
}
if (bamonth==9) {
var monthdate = October;
}
if (bamonth==10) {
var monthdate = November;
}
if (bamonth==11) {
var monthdate = December;
}
document.write('test')
</script>
and for some reason... it's not writing "test".. and it doesn't show any errors.. Why is it not working? .. I'm kindof new at JavaScript

Thanks
dereko04011 is offline   Reply With Quote
Old Aug 8th, 2005, 9:01 PM   #2
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
Is that the whole thing? I mean, do you have a head and a body and all that?
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Old Aug 9th, 2005, 1:59 AM   #3
dereko04011
Newbie
 
Join Date: Jan 2005
Posts: 9
Rep Power: 0 dereko04011 is on a distinguished road
Yes it does.. and it still didn't do anything..
dereko04011 is offline   Reply With Quote
Old Aug 9th, 2005, 8:32 AM   #4
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
This code woiks fer me. You can see it in action here.
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Date Thangy</title>
<script type="text/javascript">
adate = new Date()
var badaydate = adate.getDay()
var numdate = adate.getDate()
var bamonthdate = adate.getMonth()
var yeardate = adate.getFullYear()
if (badate == 1) {
	var daydate = Monday;
}
if (badate==0) {
	var daydate = Sunday;
}
if (badate==2) {
	var daydate = Tuesday;
}
if (badate==3) {
	var daydate = Wednesday;
}
if (badate==4) {
	var daydate = Thursday;
}
if (badate==5) {
	var daydate = Friday;
}
if (badate==6) {
	var daydate = Saturday;
}
if (bamonth==0) {
	var monthdate = January;
}
if (bamonth==1) {
	var monthdate = February;
}
if (bamonth==2) {
	var monthdate = March;
}
if (bamonth==3) {
	var monthdate = April;
}
if (bamonth==4) {
	var monthdate = May;
}
if (bamonth==5) {
	var monthdate = June;
}
if (bamonth==6) {
	var monthdate = July;
}
if (bamonth==7) {
	var monthdate = August;
}
if (bamonth==8) {
	var monthdate = September;
}
if (bamonth==9) {
	var monthdate = October;
}
if (bamonth==10) {
	var monthdate = November;
}
if (bamonth==11) {
	var monthdate = December;
}
</script>
</head>

<body>
<script type="text/javascript">
document.write('test')
</script>
</body>
</html>
That said, note a couple things, here. Suppose badate == 1. You set daydate = Monday. First of all, do you mean "Monday"? Secondly, after that, you go ahead and test it again to see if it's equal to 2, 3, etc. That's just a waste, considering the success of the first test assures you that those tests aren't necessary. Learn about the "else" or "switch" statements. Thirdly, I realize that your code is incomplete, so perhaps you have some utility in mind for later, but declaring a var locally (inside the function) means it will disappear and be unusable when the function returns. If you have plans for "daydate", et al, either return them, use them globally (not best), or use them inside the function.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Old Aug 9th, 2005, 3:16 PM   #5
dereko04011
Newbie
 
Join Date: Jan 2005
Posts: 9
Rep Power: 0 dereko04011 is on a distinguished road
Thanks. I figured the problem.. but forgot to post it I just had to quote the if variables. And I did it in a easier way using arrays:

<script type="text/javascript">
var dayNames = new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");

var monthNames = new Array("January","February","March","April","May","June","July",
                           "August","September","October","November","December");

var dt = new Date();
var y  = dt.getYear();

if (y < 1000) y +=1900;

document.write("<b>Todays date is:</b><br>"+dayNames[dt.getDay()] + ", " + monthNames[dt.getMonth()] + " " + dt.getDate() + ", " + y +"<br>");
Thats easy and simple.. for some reasons I can't do JavaScript conditional statements right.. cause I had multiple IF statements and the last IF statement had 'else' in it and it wouldn't work for some reason.. so I need to refresh myself with JavaScript.
dereko04011 is offline   Reply With Quote
Old Aug 9th, 2005, 3:38 PM   #6
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
This might piss you off, but when you come to a forum like this and ask for free help, you should give some feedback if a profferred solution works or if you solve the problem yourself. I only invested about 15 minutes in this, but I'd rather not have done it at all if it was for naught. You didn't even apologize for being unthoughtful. That pisses ME off. Kiss my ass and get someone else to analyze your poor coding.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Old Aug 9th, 2005, 10:44 PM   #7
dereko04011
Newbie
 
Join Date: Jan 2005
Posts: 9
Rep Power: 0 dereko04011 is on a distinguished road
Wow what is your problem. I'm sorry that I was busy but I had complications because I had to drive to the airport, so I COULDN'T reply, but then you already replied your SOLUTION. And yes I do thank you for the feedback. But you don't have to be a dick about this. I'm new, take it easy. Jesus christ.. you need to know the WHOLE story before you talk stuff that you DONT know.
dereko04011 is offline   Reply With Quote
Old Aug 9th, 2005, 11:55 PM   #8
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
I don't give a rats if you had to go to the airport, you apparently got back and made your post. MY post came after YOUR second post, in which you had the opportunity to say, oh, I found the solution, but thanks for those offered. So you send me a PM as well as this post? Grow the fuck up and realize that when you get free help you should at least show SOME appreciation. Stick it up your ass, dumb fucker, your indignation cuts no water with me.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Old Aug 10th, 2005, 8:48 AM   #9
dereko04011
Newbie
 
Join Date: Jan 2005
Posts: 9
Rep Power: 0 dereko04011 is on a distinguished road
Do you NOT see me saying thanks in the second post? I quote:
"Thanks. I figured the problem.. but forgot to post it I just had to quote the if variables. And I did it in a easier way using arrays:"

so yea..
dereko04011 is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 5:02 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC