Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

date validation and Netscape 4.x

Status
Not open for further replies.

meriwether

Programmer
Mar 7, 2003
23
US
The following script appears to work in NS6/7 and IE6, but Netscape 4.x is complaining, DaysObject.add is not a function (line 92). Any assistance on getting this to work would be appreciated. Here's the entire page:

<html>
<head>

<style type=&quot;text/css&quot;>
<!--
body, select, input { font-family: arial; font-size: 8pt; }
//-->
</style>

<script language=&quot;JavaScript&quot;>
<!--
//////////////////////////////////////////////

//set todays date
Now = new Date();
NowDay = Now.getDate();
NowMonth = Now.getMonth();
NowYear = Now.getYear();
if (NowYear < 2000) NowYear += 1900; //for Netscape

// HOW MANY DAYS IN A MONTH INCLUDING LEAP YEARS
function DaysInMonth(WhichMonth, WhichYear)
// added 1 to each month to account for the <option &quot;Day&quot; value
{
var DaysInMonth = 32;
if (WhichMonth == &quot;Apr&quot; || WhichMonth == &quot;Jun&quot; || WhichMonth == &quot;Sep&quot; || WhichMonth == &quot;Nov&quot;) DaysInMonth = 31;
if (WhichMonth == &quot;Feb&quot; && (WhichYear/4) != Math.floor(WhichYear/4)) DaysInMonth = 29;
if (WhichMonth == &quot;Feb&quot; && (WhichYear/4) == Math.floor(WhichYear/4)) DaysInMonth = 30;
return DaysInMonth;
}

// CHANGE THE AVAILABLE DAYS IN A MONTHS
function ChangeOptionDays(Which) {

DaysObject = eval(&quot;document._pffform.&quot; + Which + &quot;Day&quot;);
MonthObject = eval(&quot;document._pffform.&quot; + Which + &quot;Month&quot;);
YearObject = eval(&quot;document._pffform.&quot; + Which + &quot;Year&quot;);

Month = MonthObject[MonthObject.selectedIndex].text;
Year = YearObject[YearObject.selectedIndex].text;

DaysForThisSelection = DaysInMonth(Month, Year);
CurrentDaysInSelection = DaysObject.length;
if (CurrentDaysInSelection > DaysForThisSelection) {

for (i=0; i<(CurrentDaysInSelection-DaysForThisSelection); i++)
{
DaysObject.options[DaysObject.options.length - 1] = null
}
}
if (DaysForThisSelection > CurrentDaysInSelection) {

for (i=0; i<(DaysForThisSelection-CurrentDaysInSelection); i++)
{
// NewOption = new Option(DaysObject.options.length +1);
// removed the +1 feature from above to acctount for <option &quot;Day&quot; value
NewOption = new Option(DaysObject.options.length);
DaysObject.add(NewOption);
}
}
if (DaysObject.selectedIndex < 0) DaysObject.selectedIndex == 0;
}

// WRITE OPTION YEARS PLUS X
function WriteYearOptions(YearsAhead) {

// modified to write option values
line = &quot;&quot;;
// added for &quot;Year&quot; to show up as first option -- remove if not needed
line += &quot;<option value='0'>Year</option>&quot;; // add &quot;Year&quot; option
for (i=0; i<YearsAhead; i++)
{
optVal = NowYear +i; // create variable for option value
// line += &quot;<OPTION>&quot;;
line += &quot;\n<OPTION value='&quot; + optVal + &quot;'>&quot;; // add value to each option
line += NowYear + i +&quot;</option>&quot;;
}
return line;
}

//////////////////////////////////////////////
// CHECK DATES

// SET VALIDDATE AS CURRENT DATE PLUS REQUIRED DAYS
var noticeReq = 30; // 30 days notice required
var temp = new Date(Now.setDate(Now.getDate() + noticeReq));
validDate = (temp.getMonth()+1) + &quot;/&quot; + temp.getDate() + &quot;/&quot; + temp.getFullYear();
validDate = new Date(validDate);

validDate = Date.UTC(validDate);

function checkDRDates() {

// VARIABLES

var departMonth = document._pffform.DepartureDateMonth.options[document._pffform.DepartureDateMonth.selectedIndex].value;
var departDay = document._pffform.DepartureDateDay.options[document._pffform.DepartureDateDay.selectedIndex].value;
var departYear = document._pffform.DepartureDateYear.options[document._pffform.DepartureDateYear.selectedIndex].value;

var returnMonth = document._pffform.ReturnDateMonth.options[document._pffform.ReturnDateMonth.selectedIndex].value;
var returnDay = document._pffform.ReturnDateDay.options[document._pffform.ReturnDateDay.selectedIndex].value;
var returnYear = document._pffform.ReturnDateYear.options[document._pffform.ReturnDateYear.selectedIndex].value;

alert(departMonth + &quot;/&quot; + departDay + &quot;/&quot; + departYear + &quot;\n&quot; + returnMonth + &quot;/&quot; + returnDay + &quot;/&quot; + returnYear);

// CHECK FOR DEPARTURE AND RETURN ENTRIES

if ((departDay == 0) || (departMonth == 0) || (departYear == 0)) {
alert(&quot;Please select a Departure Date. Thank you.&quot;);
return false;
} else {
if ((returnDay == 0) || (returnMonth == 0) || (returnYear == 0)) {
alert(&quot;Please select a Return Date. Thank you.&quot;);
return false;
} else {

// CREATE A FULL DATE MONTH/DATE/YEAR
departDate = new Date(departMonth + '/' + departDay + '/' + departYear);
returnDate = new Date(returnMonth + '/' + returnDay + '/' + returnYear);

departDate = Date.UTC(departDate);
returnDate = Date.UTC(returnDate);

// CHECK IF DEPART DATE IS LESS THAN 30 DAYS FROM TODAY'S DATE
if (departDate < validDate) {
alert (&quot;The Departure Date is not 30 or more days from Today's date.\nThe program rules state that the flight must be 30 days or more from today.\nPlease review the rules, and make the appropriate changes. Thank you.&quot;);
return false;
} else {

// CHECK IF DEPARTURE DATE PRECEEDS RETURN DATE
if (departDate > returnDate) {
alert (&quot;The Return date precedes the Departure Date.\nPlease check your Departure and Return Dates.\n&quot;);
return false;
} else {

// CHECK IF TWO DATES ARE SAME, CONFIRM IF SO
if (departDate == returnDate) {
confirm (&quot;The Departure Date is the same as the Return Date.\nIf this is correct, please click ''OK''.\nIf you would like to make changes, please click ''Cancel'' and make the appropriate changes.\nThank you.&quot;);
return true;
} else {
// all is well
alert(&quot;Dates are OK&quot;); // remove for production
}
}
}
}
}
}

// -->
</script>

</head>

<body>

<form name=&quot;_pffform&quot; method=post>

D Date:
<select name=&quot;DepartureDateMonth&quot; onchange=&quot;ChangeOptionDays('DepartureDate')&quot;>
<option value=&quot;0&quot;>Month</option>
<option value=&quot;1&quot;>Jan</option>
<option value=&quot;2&quot;>Feb</option>
<option value=&quot;3&quot;>Mar</option>
<option value=&quot;4&quot;>Apr</option>
<option value=&quot;5&quot;>May</option>
<option value=&quot;6&quot;>Jun</option>
<option value=&quot;7&quot;>Jul</option>
<option value=&quot;8&quot;>Aug</option>
<option value=&quot;9&quot;>Sep</option>
<option value=&quot;10&quot;>Oct</option>
<option value=&quot;11&quot;>Nov</option>
<option value=&quot;12&quot;>Dec</option>
</select>

<select name=&quot;DepartureDateDay&quot;>
<option value=&quot;0&quot;>Day</option>
<OPTION value=&quot;1&quot;>1</option>
<OPTION value=&quot;2&quot;>2</option>
<OPTION value=&quot;3&quot;>3</option>
<OPTION value=&quot;4&quot;>4</option>
<OPTION value=&quot;5&quot;>5</option>
<OPTION value=&quot;6&quot;>6</option>
<OPTION value=&quot;7&quot;>7</option>
<OPTION value=&quot;8&quot;>8</option>
<OPTION value=&quot;9&quot;>9</option>
<OPTION value=&quot;10&quot;>10</option>
<OPTION value=&quot;11&quot;>11</option>
<OPTION value=&quot;12&quot;>12</option>
<OPTION value=&quot;13&quot;>13</option>
<OPTION value=&quot;14&quot;>14</option>
<OPTION value=&quot;15&quot;>15</option>
<OPTION value=&quot;16&quot;>16</option>
<OPTION value=&quot;17&quot;>17</option>
<OPTION value=&quot;18&quot;>18</option>
<OPTION value=&quot;19&quot;>19</option>
<OPTION value=&quot;20&quot;>20</option>
<OPTION value=&quot;21&quot;>21</option>
<OPTION value=&quot;22&quot;>22</option>
<OPTION value=&quot;23&quot;>23</option>
<OPTION value=&quot;24&quot;>24</option>
<OPTION value=&quot;25&quot;>25</option>
<OPTION value=&quot;26&quot;>26</option>
<OPTION value=&quot;27&quot;>27</option>
<OPTION value=&quot;28&quot;>28</option>
<OPTION value=&quot;29&quot;>29</option>
<OPTION value=&quot;30&quot;>30</option>
<OPTION value=&quot;31&quot;>31</option>
</select>

<select name=&quot;DepartureDateYear&quot; onchange=&quot;ChangeOptionDays('DepartureDate')&quot;>
<script language=&quot;JavaScript&quot;>
document.write(WriteYearOptions(03));
</script>
</select>

<br>
<br>
R Date:
<select name=&quot;ReturnDateMonth&quot; onchange=&quot;ChangeOptionDays('ReturnDate')&quot;>
<option value=&quot;0&quot;>Month</option>
<option value=&quot;1&quot;>Jan</option>
<option value=&quot;2&quot;>Feb</option>
<option value=&quot;3&quot;>Mar</option>
<option value=&quot;4&quot;>Apr</option>
<option value=&quot;5&quot;>May</option>
<option value=&quot;6&quot;>Jun</option>
<option value=&quot;7&quot;>Jul</option>
<option value=&quot;8&quot;>Aug</option>
<option value=&quot;9&quot;>Sep</option>
<option value=&quot;10&quot;>Oct</option>
<option value=&quot;11&quot;>Nov</option>
<option value=&quot;12&quot;>Dec</option>
</select>

<select name=&quot;ReturnDateDay&quot;>
<option value=&quot;0&quot;>Day</option>
<OPTION value=&quot;1&quot;>1</option>
<OPTION value=&quot;2&quot;>2</option>
<OPTION value=&quot;3&quot;>3</option>
<OPTION value=&quot;4&quot;>4</option>
<OPTION value=&quot;5&quot;>5</option>
<OPTION value=&quot;6&quot;>6</option>
<OPTION value=&quot;7&quot;>7</option>
<OPTION value=&quot;8&quot;>8</option>
<OPTION value=&quot;9&quot;>9</option>
<OPTION value=&quot;10&quot;>10</option>
<OPTION value=&quot;11&quot;>11</option>
<OPTION value=&quot;12&quot;>12</option>
<OPTION value=&quot;13&quot;>13</option>
<OPTION value=&quot;14&quot;>14</option>
<OPTION value=&quot;15&quot;>15</option>
<OPTION value=&quot;16&quot;>16</option>
<OPTION value=&quot;17&quot;>17</option>
<OPTION value=&quot;18&quot;>18</option>
<OPTION value=&quot;19&quot;>19</option>
<OPTION value=&quot;20&quot;>20</option>
<OPTION value=&quot;21&quot;>21</option>
<OPTION value=&quot;22&quot;>22</option>
<OPTION value=&quot;23&quot;>23</option>
<OPTION value=&quot;24&quot;>24</option>
<OPTION value=&quot;25&quot;>25</option>
<OPTION value=&quot;26&quot;>26</option>
<OPTION value=&quot;27&quot;>27</option>
<OPTION value=&quot;28&quot;>28</option>
<OPTION value=&quot;29&quot;>29</option>
<OPTION value=&quot;30&quot;>30</option>
<OPTION value=&quot;31&quot;>31</option>
</select>


<select name=&quot;ReturnDateYear&quot; onchange=&quot;ChangeOptionDays('ReturnDate')&quot;>
<script language=&quot;JavaScript&quot;>
document.write(WriteYearOptions(03));
</script>

</select>

<!-- type set to button for testing only -->
<p><input type=&quot;button&quot; value=&quot;Submit&quot; onclick=&quot;checkDRDates()&quot;;></p>

<p><font color=&quot;blue&quot;>Notes:

<p>This script checks for:
<ul>
<li>D Date is 30+ days from Today's date</li>
<li>D Date is not same as R Date, Confirm OK if so</li>
<li>R Date does not precede D Date</li>
<li>Days are adjusted per month/year</li>
<li>Year is written specified # of years based on current year</li>
</ul></font>

<p><font color=&quot;red&quot;><b>Currently debuggin &quot;null&quot; issue in Netscape 4.x</b></font><font color=&quot;blue&quot;>
<p>Works and tested with the following browsers:
<ul>
<li>IE 6</li>
<li>NS 6.2</li>
</ul>
</font>

</form>

</body>

</html>
 
if someone would ask you for help to add bycicle pedals on their Ford Mustang wouldn't you ask them why?

This is why I am asking. Why support NS4? Mostly everyone knows it doubles, nearly triples the amount of work and time when developing web pages or applications for such a small per centage of the web population.

If NS4 was their only choice I would understand your desire to support them but the latest versions of Netscape are free, faster and better (in supporting web standards) than that old clunky NS4.

Why such obstination? Gary Haran
 
any one else have an idea of how i can get this to work in NS4.x? I think the issue is in the function ChangeOptionDays(Which). i'm also having troubles with feb 29, 2004 (in IE6), the day isn't getting a value. any assistance is greatly appreciated.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top