Solved

I need some dates

Posted on 2002-07-18
9
177 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
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
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

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

Suggested Solutions

In my daily work (mainly using ASP.net), I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
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…

821 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