Trevor Lawrence said:
Alven said:
Sorry, I forgot to say when the users wish to select by number they
select from drop down menu contains the numbers starting from 1 till the
last number of today and appear the number of tomorrow and so on.
[snip}
Anyway I'll think about how both date and number selection can be done.
I have managed to write some code which asks for either date or number
Date is set to current but can be altered.
If Number is left blank a file will be opened based on the date.
e.g
8 Dec 2007 is file20071208
7 Dec 2007 is file20071207
etc.
Number is set to blank, but any entry here will overwrite the date and
bring up a file based on the number
1 is file20071126
2 is file20071127
3 is file20071128
4 is file20071129
etc.
If the number is greater than the number of days since 26Nov, or less than
zero, an alert prints and you are returned to correct it
Before the file is opened, an alert appears which allows the load to be
cancelled
If the file does not exist, then a standard "file not found" panel will
appear and the back button is needed to return
You may need to change the file naming convention to suit you.
Note that this does NOT use a drop down list but does avoid the problem of
a very large list. Provided all the files from 26Nov to current date
exist, any number entered will work
But I haven't solved the problem of entering anything other than a number
in the Number field
0 is treated as blank and the Date option is used
Any number less than 0 or greater than the available number is rejected
BUT a character is not rejected and will result in trying to open an
invalid file
This is the code
<html>
<head>
<script type ="text/javascript">
var now = new Date()
var firstdate = new Date()
var newdate = new Date()
firstdate.setFullYear(2007,10,26)
function init(){
var yearno = now.getYear() ,
monthno = now.getMonth() + 1 ,
dateno = now.getDate()
monthno = (monthno < 10) ? '0' + monthno : monthno
dateno = (dateno < 10) ? '0' + dateno : dateno
with (document){
getElementById("val1").value = dateno
getElementById("val2").value = monthno
getElementById("val3").value = yearno
getElementById("val4").value=""
}
}
function loadfile(){
var fname
with (document){
var number = getElementById("val4").value*1
if (number==""){
fname = 'file'
+ getElementById("val3").value
+ getElementById("val2").value
+ getElementById("val1").value
+ '.html'
} // end if
else{
newdate.setFullYear(firstdate.getFullYear(),firstdate.getMonth(),firstdate.getDate()
+ number - 1)
var from_first = (now - firstdate)/(24*60*60*1000) + 1
if (number > from_first||number < 1) {
alert('number ' + number + ' not in range 1 to ' + from_first )
return
}
var newyear = newdate.getFullYear()
var newmonth = newdate.getMonth()+1
var newday = newdate.getDate()
newmonth = (newmonth < 10) ? '0' + newmonth : newmonth
newday = (newday < 10) ? '0' + newday : newday
var fname = 'file' + String(newyear) +
String(newmonth)+String(newday) + '.html'
getElementById("val4").value = number + ': ' + fname
} // end else
if (confirm('Do you wish to load ' + fname + ' ?'
+ '\nAfter viewing, or if file name incorrect, please press the Back
button'))
location.href = fname
else
getElementById("loadmsg").innerHTML = 'Load of ' + fname + '
cancelled'
getElementById("val4").value = ""
} // end with
} // end function
</script>
</head>
<body onload="init();">
<form name="form1" action="">
Enter date or type a number<br>
<table>
<tr>
<td>Day: </td>
<td><input type="text" id="val1" value=""/></td>
</tr>
<tr>
<td>Month: </td>
<td><input type="text" id="val2" value="" /></td>
</tr>
<tr>
<td>Year: </td>
<td><input type="text" id="val3" value="" /></td>
</tr>
<tr>
<td>Or Number: </td>
<td><input type="text" id="val4" value=""/></td>
</tr>
<tr>
<td colspan="2" id="loadmsg"></td>
</tr>
</table>
<input type="button" value="Get File" onclick="loadfile()" />
</form>
</body>
</html>
--
Trevor Lawrence
Canberra
Microsoft MVP - FrontPage
MVP Web Site
http://trevorl.mvps.org