?
Solved

I need some dates

Posted on 2002-07-18
9
Medium Priority
?
183 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

This article discusses how to implement server side field validation and display customized error messages to the client.
A while back, I ran into a situation where I was trying to use the calculated columns feature in SharePoint 2013 to do some simple math using values in two lists. Between certain data types not being accessible, and also with trying to make a one to…
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…

650 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