Solved

I need some dates

Posted on 2002-07-18
9
173 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
 
LVL 18

Expert Comment

by:bobbit31
ID: 7163064
try:

document.frmE.txtID1.value = DayAdd(new Date(intMonth + "/" + intDay + "/" + strYear),7));
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
This article discusses how to create an extensible mechanism for linked drop downs.
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…

920 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

17 Experts available now in Live!

Get 1:1 Help Now