473,396 Members | 2,010 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Capturing a "datestamp", adding days to the date and send it with a form

Hi,

Will appreciate bareing with me as I'm not very dextrouse on some areas of javascripting.

I have a page with a form, and I'm wanting to:
1. Capture the current date (today)
2. Add 15 days to the date value generated
3. Send it as a value in the form

Have tried all sorts of manners, but what has only worked to this moment is:

<body onload="document.forms[0].elements['DATE'].value = new Date()">

and then on the form...

<form action="http://"
name="subscribeForm" method="post" onSubmit="return checkForm();">
<input type="hidden" name="DATE" />
...

I'm getting all the date information though (Wed Sep 08 2010 18:25:26 GMT-0600), and then would actually wish to not only set it up so that it only shows: Sep 08 2010; but also add 15 days to this value before sending it with form.

Any help will be greatly appreciated.

Best!
Max
Sep 9 '10 #1
4 1391
Dormilich
8,658 Expert Mod 8TB
I don’t know whether there is a better possibility, but you can instantiate a new date from timestamps.
Expand|Select|Wrap|Line Numbers
  1. // today’s date
  2. var today = new Date;
  3. // 15 days in milliseconds
  4. var fortnight = 1296000000;
  5. // create new date from timestamp
  6. var in15days = new Date(today.getTime() + fortnight);
Sep 9 '10 #2
Hi Dormilich, thank you.

Could you please advise how would you go about an implement these though. I guess it's 101, but I'm at that level :S Thanks
Sep 9 '10 #3
Dormilich
8,658 Expert Mod 8TB
using the lazy way (<script> block at the end of the document)

Expand|Select|Wrap|Line Numbers
  1. function futureDate(days)
  2. {
  3.     return new Date((new Date).getTime() + (days * 24 * 3600000));
  4. }
  5. document.forms[0].elements['DATE'].value = futureDate(15);
Sep 9 '10 #4
Awesome Dormilich! Thank you very much!
All the best!
Max
Sep 9 '10 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: kinne | last post by:
The following code is supposed to reverse the date in "yyyy-mm-dd" format, but it produces different results in Firefox 1.0 and in Internet Explorer 6SP1. In Firefox, the result is correct...
6
by: eric.goforth | last post by:
Hello, I'm calling a VB.NET 2003 dll that's registered in COM+. I've added a reference to it in a VB6 DLL that I'm calling from a Classic ASP page. Previously I was able to attach to my .NET...
1
by: Parsed Cheese | last post by:
After two days I am at wits end, but I am too OCD'ed to give up. Please tell me what I have got wrong because no Validation Error is being thrown. The element: "<datestamp>I should...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.