codetoad.com
  ASP Shopping CartForum & BBS
  - all for $20 from CodeToad Plus!
  
  Home || ASP | ASP.Net | C++/C# | DHTML | HTML | Java | Javascript | Perl | VB | XML || CodeToad Plus! || Forums || RAM 
Search Site:
Search Forums:
  Incrementing a date field using javascript via prompt  DoctorGonzo at 15:53 on Thursday, April 15, 2004
 

Hi Guys,

I'm trying to increment a date field by X number of days.

X is captured by a prompt and stored in variable [dateday].

The field on the form is called ExpiryDate

My function is working, but it is replacing ExpiryDate's value with TODAY's date incremented by X instead of ExpiryDate's existing value incremented by X.

To summarise, I have this field on a form.

It might have a value of 21/04/2004

When prompted I type in a number... say 2 to increase expirydate by 2 days.

Expiry date gets replaced with 17/04/2004 (today - 15th, plus 2) instead of 23/04/2004 (expirydate's value plus 2)

Here is script buddy..... hope you can help! think I need to do somthing with the var time = new Date() line??

Gonzo

function ExtendDate(){
var time = new Date();
var dateday = prompt("Please enter number of days to increase expiry date
by","");
days =parseInt(dateday);
time.setTime(time.getTime()+days*24*60*60*1000)
var day = time.getDate();
var month =parseInt(time.getMonth()+1);
var year = time.getYear();
if (dateday != null && dateday != "")
{
alert("This will increase date object by " + dateday + " days!");
document.forms[0].ExpiryDate.value=day+'/index.html'+month+'/index.html'+year;
}

}









CodeToad Experts

Can't find the answer?
Our Site experts are answering questions for free in the CodeToad forums








Recent Forum Threads
•  Re: Insert Contents of .txt file into a .html page
•  Re: Using Lucene or Solr ?
•  com ports in windows 7
•  How do I use PHP with Solr?
•  Need to enter XML content into HTML formatted email document
•  Lightweight components reuses its parents graphical units. Heavyweight components
•  lightweight and heavyweight component
•  array of struct
•  matrix prblm in java


Recent Articles
ASP GetTempName
Decode and Encode UTF-8
ASP GetFile
ASP FolderExists
ASP FileExists
ASP OpenTextFile
ASP FilesystemObject
ASP CreateFolder
ASP CreateTextFile
Javascript Get Selected Text


© Copyright codetoad.com 2001-2010