?
Solved

I need some dates

Posted on 2002-07-18
9
Medium Priority
?
181 Views
Last Modified: 2012-05-04
Ha ha, you thought I was a despirate fat man looking for a lover.  

This is pretty easy, I just don't feel like looking this stuff up and implementing it.  So here's bunch of points for a cut and paste answer.

With the following HTML, I need a javascript that will add a week to each date.  For example if I enter in today's date into txtThisDate, it will automatically populate txtID1 to 7/25/02, txtID2 to 8/1/02, txtID3 to 8/8/02 and txtID4 to 8/15/02.  They will be able to change the txtID(n).  I'm assuming the txtThisDate will be an onBlur() command.

Code sample:

self.asp
--------

...
<script language="javascript" src="/include/signup_checkForm.js"></script>
<script language="javascript" src="/include/erythro.js"></script>
...

...
<form method="post" action="self.asp" name="frmE" onSubmit="validateform(frmE)">
<input TYPE="text" SIZE="9" name="txtThisDate" onBlur="isDate(this,'This Date')" value="MM/DD/YYYY">
<input TYPE="text" SIZE="9" onBlur="isDate(this,'1 Injection Date')" name="txtID1">
<input TYPE="text" SIZE="9" onBlur="isDate(this,'2 Injection Date')" name="txtID2">
<input TYPE="text" SIZE="9" onBlur="isDate(this,'3 Injection Date')" name="txtID3">
<input TYPE="text" SIZE="9" onBlur="isDate(this,'4 Injection Date')" name="txtID4">
<input type = submit>
</form>
...

erythro.js
----------

function validateform(form)
{    
     if (form.ThisDate.value == ""){
          alert("Enter a date");
          form.txtName.focus();
     return false
     }    
  form.submit();
}

signup_checkForm.js
-------------------
function chkdate(objName) {
   //all this does is validate the date and change it to a proper format
}

0
Comment
Question by:thunderchicken
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
9 Comments
 
LVL 18

Accepted Solution

by:
bobbit31 earned 1200 total points
ID: 7162848
function DateAdd(startDate, numDays, numMonths, numYears)
{
     var returnDate = new Date(startDate.getTime());
     var yearsToAdd = numYears;
     
     var month = returnDate.getMonth()     + numMonths;
     if (month > 11)
     {
          yearsToAdd = Math.floor((month+1)/12);
          month -= 12*yearsToAdd;
          yearsToAdd += numYears;
     }
     returnDate.setMonth(month);
     returnDate.setFullYear(returnDate.getFullYear()     + yearsToAdd);
     
     returnDate.setTime(returnDate.getTime()+60000*60*24*numDays);
     
     return returnDate;

}

function YearAdd(startDate, numYears)
{
          return DateAdd(startDate,0,0,numYears);
}

function MonthAdd(startDate, numMonths)
{
          return DateAdd(startDate,0,numMonths,0);
}

function DayAdd(startDate, numDays)
{
          return DateAdd(startDate,numDays,0,0);
}
0
 
LVL 11

Author Comment

by:thunderchicken
ID: 7163051
I'm getting a syntax error...

document.frmE.txtID1.value =  DayAdd((intMonth + "/" + intday + "/" + strYear), 7);
       
0
 
LVL 11

Author Comment

by:thunderchicken
ID: 7163060
Like this..

 document.frmE.txtID1.value =  DayAdd("12/12/2002", 7);
       

it says object doesn't support this method or property.

but i can do this

 document.frmE.txtID1.value =  intMonth;
       
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 18

Expert Comment

by:bobbit31
ID: 7163064
try:

document.frmE.txtID1.value = DayAdd(new Date(intMonth + "/" + intDay + "/" + strYear),7));
0
 
LVL 11

Author Comment

by:thunderchicken
ID: 7163073
That worked, however, how do I format it to MM/DD/YYYY Format.  this is all i need left and the points are yours
0
 
LVL 18

Expert Comment

by:bobbit31
ID: 7163083
function formatDateShortFormat(d) {
     return d.getDay() + "/" + d.getMonth() + "/" + d.getFullYear();
}

just pass the result of DayAdd to the above function
0
 
LVL 11

Author Comment

by:thunderchicken
ID: 7163104
getDay returns the Sunday Monday Tues value, it's getDate() FYI, but it works, thanks
0
 
LVL 18

Expert Comment

by:bobbit31
ID: 7163110
welcome, thanks for so many points ;)
0
 
LVL 11

Author Comment

by:thunderchicken
ID: 7164893
No, thank you from keeping me from looking up this stuff and being creative when it's so close to the weekend.  He he
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question