Solved

I need some dates

Posted on 2002-07-18
9
172 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
  • 5
  • 4
9 Comments
 
LVL 18

Accepted Solution

by:
bobbit31 earned 300 total points
Comment Utility
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
Comment Utility
I'm getting a syntax error...

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

Author Comment

by:thunderchicken
Comment Utility
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
 
LVL 18

Expert Comment

by:bobbit31
Comment Utility
try:

document.frmE.txtID1.value = DayAdd(new Date(intMonth + "/" + intDay + "/" + strYear),7));
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 11

Author Comment

by:thunderchicken
Comment Utility
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
Comment Utility
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
Comment Utility
getDay returns the Sunday Monday Tues value, it's getDate() FYI, but it works, thanks
0
 
LVL 18

Expert Comment

by:bobbit31
Comment Utility
welcome, thanks for so many points ;)
0
 
LVL 11

Author Comment

by:thunderchicken
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

This article shows how to create and access 2-dimensional arrays in JavaScript.  It includes a tutorial in case you are just trying to "get your head wrapped around" the concept and we'll also look at some useful tips for more advanced programmers. …
In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
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…

763 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

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now