Link to home
Start Free TrialLog in
Avatar of jriver12
jriver12

asked on

rajeev1972 , are you still around ( have a date challenge for you)

I have a form that does a lot of date calculations based off of time of month (dayofmonth), depending on the date entered in one field the calculation would add any of these values 45,15, 10,2.

the calculation also would take into consideration other fields.  

if you or any other experts would like to take the challenge I would reward a much higher amount of points (500-1000) what ever ( I trying to bribe).

I must say that I have been trying to get a solution to this issue for just over a year now and have been unsuccessful.

please help.
thanks.
Avatar of COBOLdinosaur
COBOLdinosaur
Flag of Canada image

Are you trying to generate a date pule a number of days?  Try:

today= new date();
todayPlus10 = new Date(today.valueOf()+(3600000*24*10));

Cd&
Avatar of jriver12
jriver12

ASKER

that would probably work only if today = document.myform.myfield.value;

where value would be 8/20/2002 (example only)
value could be any date.

I have been trying for a while and have failed miserably.
that would probably work only if today = document.myform.myfield.value;

where value would be 8/20/2002 (example only)
value could be any date.

I have been trying for a while and have failed miserably.
Does this not solve it:
<html><head>
<script language="JavaScript">
<!--
function setNewDate(indate) {
today= new Date(indate);
todayPlus10 = new Date(today.valueOf()+(3600000*24*10));
return todayPlus10;
}

//-->
</script>
</head>
<body>
<form name="theform">
<input name="Datein" type="text">
<input name="Dateout" type=text">
<input type="submit"
onClick="this.form.Dateout.value=setNewDate(this.form.Datein.value);return false">
</form>
</body>
</html>


Works for 8/24/2002 or 8-24-2002 or 8-24-02

That's the only formats I tested.  An invalid value returns NaN


Cd&
Oops sorry, forget that last format 8-24-02 treats the year as 1902 0n modern computers.

Cd&
COBOLdinosaur,

I have tried your solution and it calculates great.
I have two questions for you.

1. can the dateout be formated as mm/dd/yyyy?
and secondly.

would you mind taking a look at my page(code and possibly assist me in incorporating your code with mine I have tried and failed (again).
if you don't mind, can I get an email to send to.?
Formatting into a different format is no problem.  You can post the code here, or just a link to the page.  You can use the email address in my profile, but it is just as easy to post it here.

Cd&
COBOLdinosaur,

as it stands now the code works off of many conditions.

the most difficult part is when the the month changes so the the amount dateout(in your code) changes
for example
condition fields:
FPR
FPR_date
Deposit_
DepositDate
 these are the fields that need to update based on the contract date.

here are the time frames for the Dateout

if the the date is between feb and sept 1 then the fprdate or the deposit date should = 35 days from contract date

on september 1 all will be fpr = yes
and all dates thru september will be 35 days from contract date.

if the contract date is between october  1 and november 30, the fprdate = 15 days from contract date.

now if the contract date is between dec 1 and the 24 then the fprdate  = 5 days from contract date.

any contract date from the 25 of dec to thru january should = 2 days from contract date.

here is the code (untidy as it may be)

if you have any questions let me know.


<!--- Clear cache --->
<cfheader name="Cache-control" value="no-store">
<!--- alter js at own risk make sure you have studied --->
<SCRIPT type="text/javascript" language="JavaScript1.2">
<!-- calculate currentdate string -->

function formatDate(date) {
var d  = date.getDate(); // set the need by date time frame
var day = (d < 10) ? '0' + d: d;
var m = date.getMonth() + 1;
var month = (m < 10) ? '0' + m : m;
var yy = date.getYear();
var year = (yy < 1000) ? yy + 1900 : yy;
var dateStr = month + "/" + day + "/" + year;
return dateStr;
}
<!-- check the form and do the calculations
function CheckForm(){
var bl = (document.boothinformation.BT_B1_Dim_1.value);
var bw = (document.boothinformation.BT_B1_Dim_2.value);
var columns = (document.boothinformation.BT_Post.value);
var ismember = (document.boothinformation.BT_Member.value);
var corners = (document.boothinformation.BT_Corners.value);
var deposit = (document.boothinformation.BT_Deposit.value);
var contractDate = (document.boothinformation.BT_ContractDate.value);
var compstate = (document.boothinformation.compstate.value);
var country = (document.boothinformation.country.value);
var cancelled = (document.boothinformation.BT_Cancelled.value);
var cancelledDate = (document.boothinformation.BT_CancelledDate.value);
var cdstat = (document.boothinformation.bt_CD_Status.value);
var cddate = (document.boothinformation.BT_cd_Date.value);
var manstat = (document.boothinformation.bt_Manual_Status.value);
var mandate = (document.boothinformation.BT_ManualDate.value);
var fpr = (document.boothinformation.BT_FPR.value);
var fprDate = (document.boothinformation.BT_FPRDate.value);
var DepositDate = (document.boothinformation.BT_DepositDate.value);
var today = new Date();
  var dayow=today.getDay()
moy=today.getMonth()
modif=2
if(moy<=9)
{
modif=35
}
if(moy==10)
{
modif=15
}
anotherDay= new Date();
DueBy=anotherDay.getTime() + 1000*60*60*24*modif
anotherDay.setTime(DueBy)
esecs=today.getTime()
if(dayow>=0 && dayow<5)
{
esecs+=60*60*24*1000
}
else
{
mult=8-dayow
esecs+=mult*60*60*24*1000
}
today.setTime(esecs)



//does the arithmatic for the total sq ft.
///changed to "must have non zero value" (not a NAN either)
if((bl >0) && (bw >0) || columns>0){
     var columnsqft = (columns * 5);
   if(bl<1 || bw<1)
     {  var totalsqft = (document.boothinformation.BT_TotalSQFT.value - (columnsqft));
    }
    else     {
var totalsqft = ((bl*bw) - (columnsqft));    
}
     document.boothinformation.BT_TotalSQFT.value = totalsqft;
      }
   
//calculates member and non member cost
totalsqft=document.boothinformation.BT_TotalSQFT.value
     if (ismember == 1){
          var totalcost = ((totalsqft * 9) + (corners * 200));
          var memdiscount = (totalsqft);
     }
      if (ismember == 0)       {
          var totalcost = ((totalsqft * 10) + (corners * 200));
          var memdiscount = (0);
     }
     
      
     document.boothinformation.BT_TotalCost.value = totalcost;
     document.boothinformation.BT_MemberD.value = memdiscount;
if (compstate == 'NA')
{
 document.boothinformation.BT_TotalCost.value = totalcost;
    }
if (compstate != 'NA')
{
 document.boothinformation.BT_TotalCost.value = (0);
 }
      
        
            <!--- calculate all with under the month of august the country =usa --->
      if ((totalsqft >= 301)  && (moy <=7)  && (country == ' USA')
        || (totalsqft >= 301 ) && (moy <=7)  && (country == 'Canada'))
        {
            document.boothinformation.BT_FPR.value = (0);
                document.boothinformation.BT_FPRDate.value = ('');
                   document.boothinformation.BT_Deposit.value = (  (totalcost) * .25);
                               document.boothinformation.BT_DepositDate.value = (formatDate(anotherDay));
     }
      
      
      
        if ((totalsqft <= 300)  && (moy <=7)  && (country == ' USA')
        || (totalsqft <= 300 ) && (moy <=7)  && (country == 'Canada')
        ||(totalsqft <= 300)  && (moy <=7)  && (country != ' USA')
        || (totalsqft <= 300 ) && (moy <=7)  && (country != 'Canada')){
         document.boothinformation.BT_FPR.value = (1);
       document.boothinformation.BT_FPRDate.value = (formatDate(anotherDay));
       document.boothinformation.BT_Deposit.value = (0);
         document.boothinformation.BT_DepositDate.value = ('');
     }
      
       if ( (moy>=8)  && (country == ' USA') || (moy>=8)  && (country == 'Canada')
       (moy>=8)  && (country != ' USA') || (moy>=8)  && (country != 'Canada')){
         document.boothinformation.BT_FPR.value = (1);
       document.boothinformation.BT_FPRDate.value = (formatDate(anotherDay));
       document.boothinformation.BT_Deposit.value = (0);
         document.boothinformation.BT_DepositDate.value = ('');
     }
      
<!---       <!---
      
      <!--- calculate all with under the month of august the country =Canada --->
      if ((totalsqft) >= 301 && (moy) <=7 && (country) == 'CANADA'){
            document.boothinformation.BT_FPR.value = (0);
                document.boothinformation.BT_FPRDate.value = ('');
                   document.boothinformation.BT_Deposit.value = (  (totalcost) * .25);
                               document.boothinformation.BT_DepositDate.value = (formatDate(anotherDay));
     }
      
      
      
         if ((totalsqft) <= 300 && (moy) <=7 && (country) == 'CANADA'){
         document.boothinformation.BT_FPR.value = (1);
       document.boothinformation.BT_FPRDate.value = (formatDate(anotherDay));
       document.boothinformation.BT_Deposit.value = (0);
         document.boothinformation.BT_DepositDate.value = ('');
     }
      
       if ( (moy) >=8 && (country) == 'CANADA'){
         document.boothinformation.BT_FPR.value = (1);
       document.boothinformation.BT_FPRDate.value = (formatDate(anotherDay));
       document.boothinformation.BT_Deposit.value = (0);
         document.boothinformation.BT_DepositDate.value = ('');
     }
      
      <!--- end canada --->
      
      <!--- calcualte all othe countries --->
      
      
      
      
      if ( (moy) >=8 && (country) != 'CANADA'||(moy) >=8 && (country) != ' USA'){
         document.boothinformation.BT_FPR.value = (1);
       document.boothinformation.BT_FPRDate.value = (formatDate(anotherDay));
       document.boothinformation.BT_Deposit.value = (0);
         document.boothinformation.BT_DepositDate.value = ('');
     }
      
if ( (moy) <=7 && (country) != 'CANADA'||(moy) <=7 && (country) != ' USA'){
         document.boothinformation.BT_FPR.value = (1);
       document.boothinformation.BT_FPRDate.value = (formatDate(anotherDay));
       document.boothinformation.BT_Deposit.value = (0);
         document.boothinformation.BT_DepositDate.value = ('');
     }        <!--- ---> ---> --->

      function dateDue(){
if ((cancelledDate == '') && (cancelled == 1)){ // checks to see if contract has been cancelled if
//so gives date of cancellation
md=new Date()
     document.boothinformation.BT_CancelledDate.value = (formatDate(md));
}
if (cancelled == 0){
     document.boothinformation.BT_CancelledDate.value = ('');
}

if ((cddate == '') && (cdstat == 1)){ // checks to see if contract has been cancelled if
//so gives date of cancellation
md=new Date()
     document.boothinformation.BT_cd_Date.value = (formatDate(md));
}
if (cdstat == 0){
     document.boothinformation.BT_cd_Date.value = ('');
}

if ((mandate == '') && (manstat == 1)){ // checks to see if contract has been cancelled if
//so gives date of cancellation
md=new Date()
     document.boothinformation.BT_ManualDate.value = (formatDate(md));
}
if (manstat == 0){
     document.boothinformation.BT_ManualDate.value = ('');
}
}

}

-->
</SCRIPT>
<!--- here is the rule breaker all business rules go out of the window  this will allow the user to modify the date in the deposit date field and the fprdate field.--->
<script language="JavaScript">
function formatDate(date) {
var d  = date.getDate(); // set the need by date time frame
var day = (d < 10) ? '0' + d: d;
var m = date.getMonth() + 1;
var month = (m < 10) ? '0' + m : m;
var yy = date.getYear();
var year = (yy < 1000) ? yy + 1900 : yy;
var dateStr = month + "/" + day + "/" + year;
return dateStr;
}
<!-- the users business rule breaker
function RuleBreaker(){
var fpr = (document.boothinformation.BT_FPR.value);
var fprDate = (document.boothinformation.BT_FPRDate.value);
var DepositDate = (document.boothinformation.BT_DepositDate.value);
var totalcost = (document.boothinformation.BT_TotalCost.value);
var today = new Date();
  var dayow=today.getDay()
moy=today.getMonth()
modif=2
if(moy<=9)
{
modif=35
}
if(moy==10)
{
modif=15
}
anotherDay= new Date();
DueBy=anotherDay.getTime() + 1000*60*60*24*modif
anotherDay.setTime(DueBy)
esecs=today.getTime()
if(dayow>=0 && dayow<5)
{
esecs+=60*60*24*1000
}
else
{
mult=8-dayow
esecs+=mult*60*60*24*1000
}
today.setTime(esecs)
anotherDay= new Date();
DueBy=anotherDay.getTime() + 1000*60*60*24*modif
anotherDay.setTime(DueBy)
esecs=today.getTime()
<!--if the fpr is yes set fpr to 1 and calculate the amount of days that it is due off of the system time only if the exception is checked -->


if (fpr ==1){
document.boothinformation.BT_FPR.value = (1);
document.boothinformation.BT_FPRDate.value = (formatDate(anotherDay));
document.boothinformation.BT_Deposit.value = (0);
document.boothinformation.BT_DepositDate.value = ('');
}
else{
<!-- if the fpr is no calculate the deposit due and its date -->
if (fpr ==0){
 document.boothinformation.BT_FPR.value = (0);
document.boothinformation.BT_FPRDate.value = ('');
document.boothinformation.BT_Deposit.value = (  (totalcost) * .25);
                               document.boothinformation.BT_DepositDate.value = (formatDate(anotherDay));
}
}
}

</script>
<!--- take numbers to text and calculate the total cost to verify  will update text in form.textver --->
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
var n = "";
function validate(input) {
if (input.length == 0) {
alert ('Please Enter A Number.');
document.boothinformation.textver.value = "";
return true;
}
else convert(input);
}
function d1(x) { // single digit terms
switch(x) {
case '0': n= ""; break;
case '1': n= " One "; break;
case '2': n= " Two "; break;
case '3': n= " Three "; break;
case '4': n= " Four "; break;
case '5': n= " Five "; break;
case '6': n= " Six "; break;
case '7': n= " Seven "; break;
case '8': n= " Eight "; break;
case '9': n= " Nine "; break;
default: n = "Not a Number";
}
return n;
}
function d2(x) { // 10x digit terms
switch(x) {
case '0': n= ""; break;
case '1': n= ""; break;
case '2': n= " Twenty "; break;
case '3': n= " Thirty "; break;
case '4': n= " Forty "; break;
case '5': n= " Fifty "; break;
case '6': n= " Sixty "; break;
case '7': n= " Seventy "; break;
case '8': n= " Eighty "; break;
case '9': n= " Ninety "; break;
default: n = "Not a Number";
}
return n;
}
function d3(x) { // teen digit terms
switch(x) {
case '0': n= " Ten "; break;
case '1': n= " Eleven "; break;
case '2': n= " Twelve "; break;
case '3': n= " Thirteen "; break;
case '4': n= " Fourteen "; break;
case '5': n= " Fifteen "; break;
case '6': n= " Sixteen "; break;
case '7': n= " Seventeen "; break;
case '8': n= " Eighteen "; break;
case '9': n= " Nineteen "; break;
default: n=  "Not a Number";
}
return n;
}
function convert(input) {
var inputlength = input.length;
var x = 0;
var teen1 = "";
var teen2 = "";
var teen3 = "";
var numName = "";
var invalidNum = "";
var a1 = ""; // for insertion of million, thousand, hundred
var a2 = "";
var a3 = "";
var a4 = "";
var a5 = "";
digit = new Array(inputlength); // stores output
for (i = 0; i < inputlength; i++)  {
// puts digits into array
digit[inputlength - i] = input.charAt(i)};
store = new Array(9); // store output
for (i = 0; i < inputlength; i++) {
x= inputlength - i;
switch (x) { // assign text to each digit
case x=9: d1(digit[x]); store[x] = n; break;
case x=8: if (digit[x] == "1") {teen3 = "yes"}
          else {teen3 = ""}; d2(digit[x]); store[x] = n; break;
case x=7: if (teen3 == "yes") {teen3 = ""; d3(digit[x])}
          else {d1(digit[x])}; store[x] = n; break;
case x=6: d1(digit[x]); store[x] = n; break;
case x=5: if (digit[x] == "1") {teen2 = "yes"}
          else {teen2 = ""}; d2(digit[x]); store[x] = n; break;
case x=4: if (teen2 == "yes") {teen2 = ""; d3(digit[x])}    
          else {d1(digit[x])}; store[x] = n; break;
case x=3: d1(digit[x]); store[x] = n; break;
case x=2: if (digit[x] == "1") {teen1 = "yes"}
          else {teen1 = ""}; d2(digit[x]); store[x] = n; break;
case x=1: if (teen1 == "yes") {teen1 = "";d3(digit[x])}    
          else {d1(digit[x])}; store[x] = n; break;
}
if (store[x] == "Not a Number"){invalidNum = "yes"};
switch (inputlength){
case 1:   store[2] = "";
case 2:   store[3] = "";
case 3:   store[4] = "";
case 4:   store[5] = "";
case 5:   store[6] = "";
case 6:   store[7] = "";
case 7:   store[8] = "";
case 8:   store[9] = "";
}
if (store[9] != "") { a1 =" Hundred, "} else {a1 = ""};
if ((store[9] != "")||(store[8] != "")||(store[7] != ""))
{ a2 =" Million, "} else {a2 = ""};
if (store[6] != "") { a3 =" Hundred "} else {a3 = ""};
if ((store[6] != "")||(store[5] != "")||(store[4] != ""))
{ a4 =" Thousand, "} else {a4 = ""};
if (store[3] != "") { a5 =" Hundred "} else {a5 = ""};
}
// add up text, cancel if invalid input found
if (invalidNum == "yes"){numName = "Invalid Input"}
else {
numName =  store[9] + a1 + store[8] + store[7]
+ a2 + store[6] + a3 + store[5] + store[4]
+ a4 + store[3] + a5 + store[2] + store[1];
}
store[1] = ""; store[2] = ""; store[3] = "";
store[4] = ""; store[5] = ""; store[6] = "";
store[7] = ""; store[8] = ""; store[9] = "";
if (numName == ""){numName = "Zero"};
document.boothinformation.BT_textver.value = "$" + numName + " and 00/100 Dollars";
return true;
}
//  End -->
</SCRIPT>



COBOLdinosaur,

as it stands now the code works off of many conditions.

the most difficult part is when the the month changes so the the amount dateout(in your code) changes
for example
condition fields:
FPR
FPR_date
Deposit_
DepositDate
 these are the fields that need to update based on the contract date.

here are the time frames for the Dateout

if the the date is between feb and sept 1 then the fprdate or the deposit date should = 35 days from contract date

on september 1 all will be fpr = yes
and all dates thru september will be 35 days from contract date.

if the contract date is between october  1 and november 30, the fprdate = 15 days from contract date.

now if the contract date is between dec 1 and the 24 then the fprdate  = 5 days from contract date.

any contract date from the 25 of dec to thru january should = 2 days from contract date.

here is the code (untidy as it may be)

if you have any questions let me know.


<!--- Clear cache --->
<cfheader name="Cache-control" value="no-store">
<!--- alter js at own risk make sure you have studied --->
<SCRIPT type="text/javascript" language="JavaScript1.2">
<!-- calculate currentdate string -->

function formatDate(date) {
var d  = date.getDate(); // set the need by date time frame
var day = (d < 10) ? '0' + d: d;
var m = date.getMonth() + 1;
var month = (m < 10) ? '0' + m : m;
var yy = date.getYear();
var year = (yy < 1000) ? yy + 1900 : yy;
var dateStr = month + "/" + day + "/" + year;
return dateStr;
}
<!-- check the form and do the calculations
function CheckForm(){
var bl = (document.boothinformation.BT_B1_Dim_1.value);
var bw = (document.boothinformation.BT_B1_Dim_2.value);
var columns = (document.boothinformation.BT_Post.value);
var ismember = (document.boothinformation.BT_Member.value);
var corners = (document.boothinformation.BT_Corners.value);
var deposit = (document.boothinformation.BT_Deposit.value);
var contractDate = (document.boothinformation.BT_ContractDate.value);
var compstate = (document.boothinformation.compstate.value);
var country = (document.boothinformation.country.value);
var cancelled = (document.boothinformation.BT_Cancelled.value);
var cancelledDate = (document.boothinformation.BT_CancelledDate.value);
var cdstat = (document.boothinformation.bt_CD_Status.value);
var cddate = (document.boothinformation.BT_cd_Date.value);
var manstat = (document.boothinformation.bt_Manual_Status.value);
var mandate = (document.boothinformation.BT_ManualDate.value);
var fpr = (document.boothinformation.BT_FPR.value);
var fprDate = (document.boothinformation.BT_FPRDate.value);
var DepositDate = (document.boothinformation.BT_DepositDate.value);
var today = new Date();
  var dayow=today.getDay()
moy=today.getMonth()
modif=2
if(moy<=9)
{
modif=35
}
if(moy==10)
{
modif=15
}
anotherDay= new Date();
DueBy=anotherDay.getTime() + 1000*60*60*24*modif
anotherDay.setTime(DueBy)
esecs=today.getTime()
if(dayow>=0 && dayow<5)
{
esecs+=60*60*24*1000
}
else
{
mult=8-dayow
esecs+=mult*60*60*24*1000
}
today.setTime(esecs)



//does the arithmatic for the total sq ft.
///changed to "must have non zero value" (not a NAN either)
if((bl >0) && (bw >0) || columns>0){
     var columnsqft = (columns * 5);
   if(bl<1 || bw<1)
     {  var totalsqft = (document.boothinformation.BT_TotalSQFT.value - (columnsqft));
    }
    else     {
var totalsqft = ((bl*bw) - (columnsqft));    
}
     document.boothinformation.BT_TotalSQFT.value = totalsqft;
      }
   
//calculates member and non member cost
totalsqft=document.boothinformation.BT_TotalSQFT.value
     if (ismember == 1){
          var totalcost = ((totalsqft * 9) + (corners * 200));
          var memdiscount = (totalsqft);
     }
      if (ismember == 0)       {
          var totalcost = ((totalsqft * 10) + (corners * 200));
          var memdiscount = (0);
     }
     
      
     document.boothinformation.BT_TotalCost.value = totalcost;
     document.boothinformation.BT_MemberD.value = memdiscount;
if (compstate == 'NA')
{
 document.boothinformation.BT_TotalCost.value = totalcost;
    }
if (compstate != 'NA')
{
 document.boothinformation.BT_TotalCost.value = (0);
 }
      
        
            <!--- calculate all with under the month of august the country =usa --->
      if ((totalsqft >= 301)  && (moy <=7)  && (country == ' USA')
        || (totalsqft >= 301 ) && (moy <=7)  && (country == 'Canada'))
        {
            document.boothinformation.BT_FPR.value = (0);
                document.boothinformation.BT_FPRDate.value = ('');
                   document.boothinformation.BT_Deposit.value = (  (totalcost) * .25);
                               document.boothinformation.BT_DepositDate.value = (formatDate(anotherDay));
     }
      
      
      
        if ((totalsqft <= 300)  && (moy <=7)  && (country == ' USA')
        || (totalsqft <= 300 ) && (moy <=7)  && (country == 'Canada')
        ||(totalsqft <= 300)  && (moy <=7)  && (country != ' USA')
        || (totalsqft <= 300 ) && (moy <=7)  && (country != 'Canada')){
         document.boothinformation.BT_FPR.value = (1);
       document.boothinformation.BT_FPRDate.value = (formatDate(anotherDay));
       document.boothinformation.BT_Deposit.value = (0);
         document.boothinformation.BT_DepositDate.value = ('');
     }
      
       if ( (moy>=8)  && (country == ' USA') || (moy>=8)  && (country == 'Canada')
       (moy>=8)  && (country != ' USA') || (moy>=8)  && (country != 'Canada')){
         document.boothinformation.BT_FPR.value = (1);
       document.boothinformation.BT_FPRDate.value = (formatDate(anotherDay));
       document.boothinformation.BT_Deposit.value = (0);
         document.boothinformation.BT_DepositDate.value = ('');
     }
      
<!---       <!---
      
      <!--- calculate all with under the month of august the country =Canada --->
      if ((totalsqft) >= 301 && (moy) <=7 && (country) == 'CANADA'){
            document.boothinformation.BT_FPR.value = (0);
                document.boothinformation.BT_FPRDate.value = ('');
                   document.boothinformation.BT_Deposit.value = (  (totalcost) * .25);
                               document.boothinformation.BT_DepositDate.value = (formatDate(anotherDay));
     }
      
      
      
         if ((totalsqft) <= 300 && (moy) <=7 && (country) == 'CANADA'){
         document.boothinformation.BT_FPR.value = (1);
       document.boothinformation.BT_FPRDate.value = (formatDate(anotherDay));
       document.boothinformation.BT_Deposit.value = (0);
         document.boothinformation.BT_DepositDate.value = ('');
     }
      
       if ( (moy) >=8 && (country) == 'CANADA'){
         document.boothinformation.BT_FPR.value = (1);
       document.boothinformation.BT_FPRDate.value = (formatDate(anotherDay));
       document.boothinformation.BT_Deposit.value = (0);
         document.boothinformation.BT_DepositDate.value = ('');
     }
      
      <!--- end canada --->
      
      <!--- calcualte all othe countries --->
      
      
      
      
      if ( (moy) >=8 && (country) != 'CANADA'||(moy) >=8 && (country) != ' USA'){
         document.boothinformation.BT_FPR.value = (1);
       document.boothinformation.BT_FPRDate.value = (formatDate(anotherDay));
       document.boothinformation.BT_Deposit.value = (0);
         document.boothinformation.BT_DepositDate.value = ('');
     }
      
if ( (moy) <=7 && (country) != 'CANADA'||(moy) <=7 && (country) != ' USA'){
         document.boothinformation.BT_FPR.value = (1);
       document.boothinformation.BT_FPRDate.value = (formatDate(anotherDay));
       document.boothinformation.BT_Deposit.value = (0);
         document.boothinformation.BT_DepositDate.value = ('');
     }        <!--- ---> ---> --->

      function dateDue(){
if ((cancelledDate == '') && (cancelled == 1)){ // checks to see if contract has been cancelled if
//so gives date of cancellation
md=new Date()
     document.boothinformation.BT_CancelledDate.value = (formatDate(md));
}
if (cancelled == 0){
     document.boothinformation.BT_CancelledDate.value = ('');
}

if ((cddate == '') && (cdstat == 1)){ // checks to see if contract has been cancelled if
//so gives date of cancellation
md=new Date()
     document.boothinformation.BT_cd_Date.value = (formatDate(md));
}
if (cdstat == 0){
     document.boothinformation.BT_cd_Date.value = ('');
}

if ((mandate == '') && (manstat == 1)){ // checks to see if contract has been cancelled if
//so gives date of cancellation
md=new Date()
     document.boothinformation.BT_ManualDate.value = (formatDate(md));
}
if (manstat == 0){
     document.boothinformation.BT_ManualDate.value = ('');
}
}

}

-->
</SCRIPT>
<!--- here is the rule breaker all business rules go out of the window  this will allow the user to modify the date in the deposit date field and the fprdate field.--->
<script language="JavaScript">
function formatDate(date) {
var d  = date.getDate(); // set the need by date time frame
var day = (d < 10) ? '0' + d: d;
var m = date.getMonth() + 1;
var month = (m < 10) ? '0' + m : m;
var yy = date.getYear();
var year = (yy < 1000) ? yy + 1900 : yy;
var dateStr = month + "/" + day + "/" + year;
return dateStr;
}
<!-- the users business rule breaker
function RuleBreaker(){
var fpr = (document.boothinformation.BT_FPR.value);
var fprDate = (document.boothinformation.BT_FPRDate.value);
var DepositDate = (document.boothinformation.BT_DepositDate.value);
var totalcost = (document.boothinformation.BT_TotalCost.value);
var today = new Date();
  var dayow=today.getDay()
moy=today.getMonth()
modif=2
if(moy<=9)
{
modif=35
}
if(moy==10)
{
modif=15
}
anotherDay= new Date();
DueBy=anotherDay.getTime() + 1000*60*60*24*modif
anotherDay.setTime(DueBy)
esecs=today.getTime()
if(dayow>=0 && dayow<5)
{
esecs+=60*60*24*1000
}
else
{
mult=8-dayow
esecs+=mult*60*60*24*1000
}
today.setTime(esecs)
anotherDay= new Date();
DueBy=anotherDay.getTime() + 1000*60*60*24*modif
anotherDay.setTime(DueBy)
esecs=today.getTime()
<!--if the fpr is yes set fpr to 1 and calculate the amount of days that it is due off of the system time only if the exception is checked -->


if (fpr ==1){
document.boothinformation.BT_FPR.value = (1);
document.boothinformation.BT_FPRDate.value = (formatDate(anotherDay));
document.boothinformation.BT_Deposit.value = (0);
document.boothinformation.BT_DepositDate.value = ('');
}
else{
<!-- if the fpr is no calculate the deposit due and its date -->
if (fpr ==0){
 document.boothinformation.BT_FPR.value = (0);
document.boothinformation.BT_FPRDate.value = ('');
document.boothinformation.BT_Deposit.value = (  (totalcost) * .25);
                               document.boothinformation.BT_DepositDate.value = (formatDate(anotherDay));
}
}
}

</script>
<!--- take numbers to text and calculate the total cost to verify  will update text in form.textver --->
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
var n = "";
function validate(input) {
if (input.length == 0) {
alert ('Please Enter A Number.');
document.boothinformation.textver.value = "";
return true;
}
else convert(input);
}
function d1(x) { // single digit terms
switch(x) {
case '0': n= ""; break;
case '1': n= " One "; break;
case '2': n= " Two "; break;
case '3': n= " Three "; break;
case '4': n= " Four "; break;
case '5': n= " Five "; break;
case '6': n= " Six "; break;
case '7': n= " Seven "; break;
case '8': n= " Eight "; break;
case '9': n= " Nine "; break;
default: n = "Not a Number";
}
return n;
}
function d2(x) { // 10x digit terms
switch(x) {
case '0': n= ""; break;
case '1': n= ""; break;
case '2': n= " Twenty "; break;
case '3': n= " Thirty "; break;
case '4': n= " Forty "; break;
case '5': n= " Fifty "; break;
case '6': n= " Sixty "; break;
case '7': n= " Seventy "; break;
case '8': n= " Eighty "; break;
case '9': n= " Ninety "; break;
default: n = "Not a Number";
}
return n;
}
function d3(x) { // teen digit terms
switch(x) {
case '0': n= " Ten "; break;
case '1': n= " Eleven "; break;
case '2': n= " Twelve "; break;
case '3': n= " Thirteen "; break;
case '4': n= " Fourteen "; break;
case '5': n= " Fifteen "; break;
case '6': n= " Sixteen "; break;
case '7': n= " Seventeen "; break;
case '8': n= " Eighteen "; break;
case '9': n= " Nineteen "; break;
default: n=  "Not a Number";
}
return n;
}
function convert(input) {
var inputlength = input.length;
var x = 0;
var teen1 = "";
var teen2 = "";
var teen3 = "";
var numName = "";
var invalidNum = "";
var a1 = ""; // for insertion of million, thousand, hundred
var a2 = "";
var a3 = "";
var a4 = "";
var a5 = "";
digit = new Array(inputlength); // stores output
for (i = 0; i < inputlength; i++)  {
// puts digits into array
digit[inputlength - i] = input.charAt(i)};
store = new Array(9); // store output
for (i = 0; i < inputlength; i++) {
x= inputlength - i;
switch (x) { // assign text to each digit
case x=9: d1(digit[x]); store[x] = n; break;
case x=8: if (digit[x] == "1") {teen3 = "yes"}
          else {teen3 = ""}; d2(digit[x]); store[x] = n; break;
case x=7: if (teen3 == "yes") {teen3 = ""; d3(digit[x])}
          else {d1(digit[x])}; store[x] = n; break;
case x=6: d1(digit[x]); store[x] = n; break;
case x=5: if (digit[x] == "1") {teen2 = "yes"}
          else {teen2 = ""}; d2(digit[x]); store[x] = n; break;
case x=4: if (teen2 == "yes") {teen2 = ""; d3(digit[x])}    
          else {d1(digit[x])}; store[x] = n; break;
case x=3: d1(digit[x]); store[x] = n; break;
case x=2: if (digit[x] == "1") {teen1 = "yes"}
          else {teen1 = ""}; d2(digit[x]); store[x] = n; break;
case x=1: if (teen1 == "yes") {teen1 = "";d3(digit[x])}    
          else {d1(digit[x])}; store[x] = n; break;
}
if (store[x] == "Not a Number"){invalidNum = "yes"};
switch (inputlength){
case 1:   store[2] = "";
case 2:   store[3] = "";
case 3:   store[4] = "";
case 4:   store[5] = "";
case 5:   store[6] = "";
case 6:   store[7] = "";
case 7:   store[8] = "";
case 8:   store[9] = "";
}
if (store[9] != "") { a1 =" Hundred, "} else {a1 = ""};
if ((store[9] != "")||(store[8] != "")||(store[7] != ""))
{ a2 =" Million, "} else {a2 = ""};
if (store[6] != "") { a3 =" Hundred "} else {a3 = ""};
if ((store[6] != "")||(store[5] != "")||(store[4] != ""))
{ a4 =" Thousand, "} else {a4 = ""};
if (store[3] != "") { a5 =" Hundred "} else {a5 = ""};
}
// add up text, cancel if invalid input found
if (invalidNum == "yes"){numName = "Invalid Input"}
else {
numName =  store[9] + a1 + store[8] + store[7]
+ a2 + store[6] + a3 + store[5] + store[4]
+ a4 + store[3] + a5 + store[2] + store[1];
}
store[1] = ""; store[2] = ""; store[3] = "";
store[4] = ""; store[5] = ""; store[6] = "";
store[7] = ""; store[8] = ""; store[9] = "";
if (numName == ""){numName = "Zero"};
document.boothinformation.BT_textver.value = "$" + numName + " and 00/100 Dollars";
return true;
}
//  End -->
</SCRIPT>



That code has got all kind of unrelated stuff in it for the rest of the application.  I don't have the time to work through it all and any changes I make might screw up the other parts of the app.  The best I can do is give you a stand alone function that will return the correct string with the "/" instead of the "-" based on the calculation rules you gave.

All you have to do is put it in the page and wherever you you need the calculation done call the setNewDate() function with the input date as the parameter and it will return the correct string for the output date, all you have to do is populate the form field with it.

Cd&


<script language="JavaScript">
<!--
   function setFormat(which)
   {
      themonth = which.getMonth() + 1;
      theyear = which.getYear();
      theday = which.getDate();
      theday=(theday<10) ? "0"+theday : theday;
      themonth=(themonth<10)? "0"+themonth : themonth;
      if (theyear<=99) theyear= "19"+theyear;
      if ((theyear>99) && (theyear<2000)) theyear+=1900;
      str = themonth+'/'+theday+'/'+theyear;
      return str;
   }

   function setNewDate(indate)
   {
      today= new Date(indate);
      rawmonth=today.getMonth();
      rawday=today.getDate();
      offset=((rawmonth==11) && (rawday<25)) ? 5 : 2;
      offset=((rawmonth>0) && (rawmonth<9)) ? 35 : offset;
      offset=((rawmonth==9)|| (rawmonth==10))? 15 : offset;
      adjusteddt= new Date(today.valueOf()+(offset*24*60*60*1000));
      formattedDate=setFormat(adjusteddt);
      return formattedDate;
    }    
//-->
</script>
Cd,
i'm testing and trying to incorp your script with mine.

I'll get back in a bit.

thanks.
they won't let me exceed 500?
it seems to be working (never a doubt) one more question and I will leave.

I am having a hard time passing the  
str = themonth+'/'+theday+'/'+theyear;
to a text field when a condition evaluates to true.

ie

if ((cancelledDate == '') && (cancelled == 1)){

// cancelled is a dropdown window that when yes(1) is selected should populate BT_CancelledDate with the current date.
the checks to see if contract has been cancelled if
//so gives date of cancellation

     document.boothinformation.BT_CancelledDate.value = str;
}
if (cancelled == 0){
     document.boothinformation.BT_CancelledDate.value = ('');
}


on the field itself I have
<select name="BT_contract_returned" onchange ="setFormat()" >
where am I wrong with this.

There are two problems that I can see:

setFormat() needs to have an argument.  To return the formatted current date use:

setFormat(new Date())

The second problem is you are trying to use str as a global variable, but it is local to the function which returns the value of str.  Two ways to solve it:

document.boothinformation.BT_CancelledDate.value=setFormat(new Date())

Or declare a global variable at the beginning of the script outside of the functions and set it:

<select name="BT_contract_returned" onchange ="somevar=setFormat(new Date())" >

Then you can use somevar to set the form field:

document.boothinformation.BT_CancelledDate.value=somevar;

One other thing you could do is declare the global variable and then use:
somevar=str; just before the return in the function.  That way the returned
value and somevar would both contain the formatted string;

Cd&
one error apperars and that is with the
var moy = today.getMonth() + 1;
it says that today is not defined.

I have tried all and got nothing but frustrated.
can you push me one more time?

function setFormat(which)
  {
  var   themonth = which.getMonth() + 1;
   var  theyear = which.getYear();
  var   theday = which.getDate();
     theday=(theday<10) ? "0"+theday : theday;
     themonth=(themonth<10)? "0"+themonth : themonth;
     if (theyear<=99) theyear= "19"+theyear;
     if ((theyear>99) && (theyear<2000)) theyear+=1900;
     str = themonth+'/'+theday+'/'+theyear;
     return str;
  }

  function setNewDate(BT_ContractDate)
  {
    var today= new Date(BT_ContractDate);
     rawmonth=today.getMonth();
     rawday=today.getDate();
     offset=((rawmonth==11) && (rawday<25)) ? 5 : 2;
     offset=((rawmonth>0) && (rawmonth<9)) ? 35 : offset;
     offset=((rawmonth==9)|| (rawmonth==10))? 15 : offset;
     adjusteddt= new Date(today.valueOf()+(offset*24*60*60*1000));
     formattedDate=setFormat(adjusteddt);
     return formattedDate;
   }    



function CheckForm(){
var bl = (document.boothinformation.BT_B1_Dim_1.value);
var bw = (document.boothinformation.BT_B1_Dim_2.value);

var moy = today.getMonth() + 1;


Thans again
ASKER CERTIFIED SOLUTION
Avatar of COBOLdinosaur
COBOLdinosaur
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Cd&
thanks for the solution.
it is what I have been trying to accomplish for some time now.

and to think that I have posted the same question about 4 times in the past year and got many viable solutions but none that did exactly what I needed.

thanks again.
Sometimes it just takes a little patient trying to find a solution.  I'm glad I could come up with what you needed.  Thanks for the A. :^)

Cd&

deserve it

thanks again.