PDA

View Full Version : date in textbox


ahmedsoliman
07-13-2002, 11:32 AM
i want to insret the current date in textbox but this code dosen't work and the value of text box will be "date()"



function date()
{
var mydate=new Date()
var year=mydate.getYear()
if (year < 1000)
year+=1900
var day=mydate.getDay()
var month=mydate.getMonth()+1
if (month<10)
month="0"+month
var daym=mydate.getDate()
if (daym<10)
daym="0"+daym
today=day+month+year;
return today;
}


<INPUT id=text3 name=text3 value="date()" >

joh6nn
07-13-2002, 01:31 PM
date is a reserved word in javascript, so you can't name a function date(). also, you can't put a javascript function into html like that. you'd have to set the value of the form using the window's onload event.

function today() {
var mydate = new Date();
var year = mydate.getFullYear();
var day = mydate.getDay();
var month = mydate.getMonth() + 1;
if (month < 10) {
month = "0" + month;
}
var daym = mydate.getDate();
if (daym < 10) {
daym = "0" + daym;
}
return ('' + day + month + year);
}

window.onload = function() {
document.theForm.text3.value = today();
}


<INPUT id=text3 name=text3>

ahmedsoliman
07-14-2002, 09:31 PM
thank you:)

Owl
07-14-2002, 11:19 PM
Hi joh6nn,

date is not a reserved word in javascript.

( •) (• )
>>V

Dave Clark
07-14-2002, 11:31 PM
Originally posted by joh6nn
date is a reserved word in javascript, so you can't name a function date().

Well, actually, since JavaScript is case-sensitive... date() would not be reserved and could be used as a user function name. Date(), however, would be the reserved form. :D

OK? :)

Owl
07-15-2002, 12:22 AM
Hi Dave,

Date is not a reserved word in javascript.
You may use it as a user function name.

( •) (• )
>>V

Dave Clark
07-15-2002, 01:34 AM
Originally posted by Owl
Date is not a reserved word in javascript.
You may use it as a user function name.

Don't be an imbecile. You're just taking up space on the server for your idiotic plays on the actual definition and normal usage of the word "reserved". So, as long as you're going to make esoteric denials of the viability of the comments of others -- without further explaining your lunacy -- then it would be far better off, for all, for you to just shove off and go play your games elsewhere. :p

So, to explain (for the simple-minded who don't know how to loosely apply a word to a situation)... "Reserved" is used in the general sense of "if you don't want to lose any of the standard JavaScript functionality." In other words... If you create your own function, called Date(), then you will no longer be able to get the normal "Date" functionality, of the JavaScript Date() constructor, by any other normal means.

OK? :)

joh6nn
07-15-2002, 06:39 PM
Dave, just so you know, i've had both Explorer and Mozilla throw errors at me, more than once, when trying to use 'date' as a variable name. only variable name i've ever had the problem with, so it's also possible that i'm misremembering, or mistaken. was with a pre 1 release of Mozilla, and i think it was with IE5, so it may no longer be an issue, if it ever was, but in my experience, 'date' acts like a reserved word, even if in theory, it isn't.

be interesting to know if anyone else has ever encountered the same, or something similar.

jkd
07-15-2002, 07:28 PM
Originally posted by Dave Clark


Don't be an imbecile. You're just taking up space on the server for your idiotic plays on the actual definition and normal usage of the word "reserved". So, as long as you're going to make esoteric denials of the viability of the comments of others -- without further explaining your lunacy -- then it would be far better off, for all, for you to just shove off and go play your games elsewhere. :p

Dave, in all Javascript references, there is a clear distinction about exactly what a reserved word is. You've linked to the references in your signature, certainly you can respect the real definition.

It is very incorrect to say that just because you shouldn't use it, means that it is reserved.

And if I was Owl, I would have taken offense at your post. Try to be nicer - though nice usage of vocabulary ;).

To quote you, "OK? :)"

Dave Clark
07-15-2002, 11:41 PM
Originally posted by jkd
Try to be nicer ...

I *can* be nicer -- when others are trying to be reasonable. Some of your recriminations should have gone the other way -- a little less one sided, in this situation.

It would have been different if the person in question had done more than just tell others that they were wrong. To tell someone that they are wrong and "walk away" is rude, crude, and immature (sorry couldn't rhyme that one :p). Such an "accusation" demands an accompanying explanation.

OK? :)

RadarBob
07-15-2002, 11:57 PM
Everyone on this thread fails the test for language lawyer certification. One must learn to play nice in courts during the heat of debate.:rolleyes:

Owl
07-16-2002, 01:05 AM
Hi Jason,

Sure glad to see one of the mods finally picking this one up.
I was beginning to think this is the regular language around here.

We both know that in the place where I come from, this
would be Daves one before last post using such language.

Any way, congrats on your new title kid.
Remember: with greater title comes greater responsibility !

( •) (• )
>>V

nolachrymose
07-16-2002, 01:15 AM
Remember: with greater title comes greater responsibility !

Hmmm...from what comic could that have been parodied? :rolleyes:

Happy coding! :)

jkd
07-16-2002, 03:37 AM
Originally posted by Dave Clark
It would have been different if the person in question had done more than just tell others that they were wrong. To tell someone that they are wrong and "walk away" is rude, crude, and immature (sorry couldn't rhyme that one :p). Such an "accusation" demands an accompanying explanation.

OK? :)

On a personal note, I would consider this part claiming your post incorrect:

Date is not a reserved word in javascript.

And this part explaining why:

You may use it as a user function name.

Albeit short, but sweet.

On an official note, could we consider this matter dropped, for the sake of maintaining the friendly atmosphere that is typical of CodingForums? :)


And on a side note, Owl and nolackymose, do I sense a JavascriptCity/PageResource migration? ;)
No offense to your native forums, but I find that CodingForums generally offers faster and more helpful replies in a greater quantity. :)

Enjoy the forums, and don't let one incident ruin your impression.