Please Mods don't kill me, I have already posted this question in the Beginners Forum but I was told over there to ask the question over here. So I'm posting it here again.
"I want to make a form for my users where they can submit deals. On the form there is a drop down menu for Exp. dates, for the dd/mm/yy. My question is how can I make that the default exp. date should change every day according to that date. If you want to see what I'm talking about you can give a look on the form at my site at http://jumpondeals.com/submitdeals.htm (right now the form is set to 11/21/00 but it doesn't change automatically).
Don't wander around in my site cause it's still under construction."
You should put the above in a function and call it with the onLoad event handler in the body tag. (If you leave it outside a function, there is a good chance, you'll end up with an object undefined or has no properties message.)
If you want to insert the current date, you can use some of the code in the following thread (posted by one of the other moderators: westmich)
Notes:
1) dependent upon how your selection list looks and is implemented, you may have to execute a reload() for netscape to redraw the screen.
2) You can also place the function directly after the selection list tag, or document.write the option in its appropriate place on the page.
Vinny
Edited by Vincent Puglia on 11-21-2000 at 09:38 PM
Hi, sorry for the link failure it was my problem as I have changed that file name, but I have corrected it now. On that page you'll see a drop down menu for the exp. date. What I want is that the default date which is filled in automatically in the drop down menu should change every day according to that days date.
Thank you so much Vincent Puglia, but can you please explain to me better what to do?
Thank you so much etlux. Do I have to enter somewhere today's date, or it takes the date from the server?
Also if I want to set the form in a way that the date should appear one day later than the current date i.e. on November 23, the form should show November 24, what should I do? (The reason why I want it this way is because an exp. date will usually not be entered for the same day).
This script takes the date from the user's system (via the browser, of course)... so it would reflect the current date as set there.
So far as I know, there's no convenient way to get the date off the server via JavaScript -- for that, you would need to go server-side.
To get the date of the following day would rather complicate the script, as you need to allow for rollovers at the end of the month, and at the end of the year.
Etlux so you can't tell me how to make that the default exp. date should be one date ahead? Please tell me. I'll appreciate it very much.
Thank you in advance!
Actually, I'm trying to think up a straighforward way to do that, which doesn't involve all sorts of arrays and exceptions to manage months of different lengths, leap years, etc.
I'm not on my primary machine, so I can't upload the code; but, if I remember right, it does work -- though the last method call may be setDate() (?) in the (yyyy,mm,dd) format. If I'm still awake when I get home, I'll check.
NS and IE process dates differently, so I may just have run afoul of that. While IE processes year dates correctly, NS adheres to the absurd standard used by Perl.
For instance,
<script>
NowDate = new Date();
Y = NowDate.getYear();
document.write(Y);
</script>
will correctly return 2000 for the year in IE -- while Netscape will return... 100.
var today = new Date();
var todayInMsecs = today.getTime();
var dayInMsecs = 60 * 60 * 24 * 1000;
var tomorrowInMsecs = todayInMsecs + dayInMsecs;
var tomorrow = new Date(tomorrowInMsecs);
If I remember right getYear() only produces the last two digits, so Netscape would come up with the Y2K thingy. getFullYear() might work, but I've never played with it.
fello9: You listening? If you want to target a date beyond today you simply need to multiply dayInMsecs by the number of days from the present
Bookmarks