counter

A

Alven

please I need some help to make an archive by date and the number of the
page as this page consider as a magazine so every day I update my index.htm
with a new contents so for example today I write magazine number 1, tomorrow
I write magazine number 2 and so on. So I need to let users search in the
archive by date or by the magazine number.
Thanks in advacne
 
T

Trevor Lawrence

Alven said:
please I need some help to make an archive by date and the number of the
page as this page consider as a magazine so every day I update my
index.htm with a new contents so for example today I write magazine number
1, tomorrow I write magazine number 2 and so on. So I need to let users
search in the archive by date or by the magazine number.
Thanks in advacne

I am not quite sure what the question is.

You can number your daily files according to some pattern and store them in
a separate folder.

You could then include these files in index.html as an in-line frame or you
could even use a link. This would need some JavaScript to decide which file
to load or link to .

As for searching for the file, this could also be done with JavaScript which
decides which file to direct the user to.

I have not done either of these, so I would need to spend some time trying
it before I could come up with a solution.

Others may have other ideas
 
A

Alven

Thanks a lot this is exactly what I need Trevor so I'm waiting for your
help.
Thanks in advance
 
T

Trevor Lawrence

Alven said:
Thanks a lot this is exactly what I need Trevor so I'm waiting for your
help.

OK.

I'll see if I can find some code that I have used. If not, I'll have to do a
little testing

IGBTY
 
T

Trevor Lawrence

Trevor Lawrence said:
OK.

I'll see if I can find some code that I have used. If not, I'll have to do
a little testing

Alven,
Here is a start

I set up a test file named "file071130.html"
<html>
<head>
</head>
<body>
This is a test file for 20071130
</body>
</html>

Here is some html which links to it, depending on today's date
<html>
<head>
<script type ="text/javascript">
function loadfile()
{
var now = new Date()
var year = now.getYear().toString().substr(2)
var monthno = now.getMonth() + 1
monthno = (monthno < 10) ? '0' + monthno : monthno
var dateno = now.getDate()
location.href = 'file' + year + monthno + dateno + '.html'
}
</script>
</head>
<body>
<a href="#" target="_self"
onclick="loadfile();return false;">Daily File</a>
</body>
</html>

To access different dates (not today) you would need a form into which the
user types a date and then the code uses that date to decide which file to
load.

I can write code for this if you need it.
 
A

Alven

Trevor thanks a lot for your help but what I need is a counter for my
index.htm for example
if today my index.htm is number (1) I need tomorrow index.htm to be number 2
etc... and to offer a form for users to browse for example back to index.htm
number 10. The target is to access different numbers of my index.htm. It is
like a magazine number 1, 2 and so on.
Thanks in advance
 
T

Thomas A. Rowe

You would need a database driven site if you want to have a single index.htm page, etc.

--
==============================================
Thomas A. Rowe
Microsoft MVP - FrontPage

http://www.Ecom-Data.com
==============================================
 
T

Trevor Lawrence

Thomas A. Rowe said:
You would need a database driven site if you want to have a single
index.htm page, etc.

Adding to what Thomas wrote.

You can only have one file named index.html
But you can link from it to various other pages.
e.g.
info1.html
info2.html
info3.html

You can create a form which asks the user which page they want to go to.

I'd be happy to write the JS to so it, but I would like more exact specs.

Do you just want to select by date?
Would there be a default? (e.g today)
How do you want to navigate to earlier pages?
If you have a form which asks for date and today is set as the default,
would this suit?

Anyway , I'll assume that the answers are
Yes
Yes - today
By selecting a date
Yes
 
T

Trevor Lawrence

Trevor Lawrence said:
I'd be happy to write the JS to so it, but I would like more exact specs.

Do you just want to select by date?
Would there be a default? (e.g today)
How do you want to navigate to earlier pages?
If you have a form which asks for date and today is set as the default,
would this suit?

Anyway , I'll assume that the answers are
Yes
Yes - today
By selecting a date
Yes

Alven,

Here is some code to load a file with a name based on the date entered.
(eg for today file 20071205.html)

If the file with that date exists, it will be opened
If not, a nomal 'file not found' message will appear
In either case, you need to press the Back buton to return to the opening
page

<html>
<head>
<script type ="text/javascript">
function gettoday(){
var now = new Date()
var yearno = now.getYear()
var monthno = now.getMonth() + 1
monthno = (monthno < 10) ? '0' + monthno : monthno
var dateno = now.getDate()
dateno = (dateno < 10) ? '0' + dateno : dateno
with (document){
getElementById("val1").value = dateno
getElementById("val2").value = monthno
getElementById("val3").value = yearno
}
}
function loadfile(){
with (document){
var fname = 'file'
+ getElementById("val3").value
+ getElementById("val2").value
+ getElementById("val1").value
+ '.html'
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'
}
}
</script>
</head>
<body onload="gettoday()">
<form name="form1" action="">
<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 colspan="2" id="loadmsg"></td>
</tr>
</table>
<input type="button" value="Get File" onclick="loadfile()" />
</form>
</body>
</html>
 
A

Alven

yes, I want to select either by date or by the number of my index.htm which
can be in this format (no_2.htm)
 
A

Alven

For example
Date: 5- 12 -2007 number: 10
tomorrow my index.htm will be
Date: 6- 12 -2007 number: 11
after tomorrow
Date: 7- 12 -2007 number: 11
So selecting by date no problem what I need if the user wish to select by
the number like number 11 how can I do it to let them choose by number and
how can I let the code increment the counter for example if today number 11
so tomorrow be number 12 or even do it manually if it is hard to do it by
automatially.

Thanks for your help and I appreciate your effort Trevor.
 
A

Alven

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.
 
T

Trevor Lawrence

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.

I feel sure this can all be done. It depends a bit on how many bells and
whistles. It looks as if any date before 26 Nov would be illegal, as would
any date after today. Of course "today" would alter as each day passed.

While a drop down list may be feasible, it would have to be recreated every
day e.g. today would have 10 entries, tomorrow 11, etc. So the list itself
would have to be generated by JavaScript. I wonder whether it would be
useful for the drop down to have both number and date displayed. If so, then
the date selection form may not be needed. In any case, some JS to
manipulate dates (e.g. calculate differences between two dates) would be
needed

What happens when the list gets too long, say after another month when there
would be 40 entries?

Some sites have a calendar where clicking on a date displays a different
result using data relevant to that date. I haven't written any code to do
this, but perhaps some of the JavaScript download sites would have an
example.

Anyway I'll think about how both date and number selection can be done.
 
T

Trevor Lawrence

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>
 
A

Alven

Thanks a lot Trevor for your help. Itried the code but it gave me error
regarding this line
<input type="button" value="Get File" onclick="loadfile()" />
So please advise
Thanks in advance

Trevor Lawrence said:
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
 
T

Trevor Lawrence

Alven said:
Thanks a lot Trevor for your help. Itried the code but it gave me error
regarding this line
<input type="button" value="Get File" onclick="loadfile()" />
So please advise
Thanks in advance

Alven,
Most odd.

I have been working on the code
a) for interest, and
b) in case you decide it is what you want. (If not, I can make changes)

I have had errors along the way, which I have corrected. But not this one

1. Can you post the text of the error, please
2. I am wondering whether the script is OK in the <head> section.

Here is my latest version of the script. It checks for a non-numeric in
Number as well as Number NOT between 26Nov and current date. (It does not
as yet check that any date entered in the Day, Month, Year boxes is in the
same range - I should do that also)

It returns no script errors using IE7

<script type ="text/javascript">
var now = new Date() ,
firstdate = new Date()
firstdate.setFullYear(2007,10,26)

function init(){
var yearno = now.getYear() ,
monthno = now.getMonth() + 1 ,
dateno = now.getDate()

with (document){
getElementById("val1").value = (dateno < 10) ? '0' + dateno : dateno
getElementById("val2").value = (monthno < 10) ? '0' + monthno : monthno
getElementById("val3").value = yearno
getElementById("val4").value=""
}
}
function loadfile(){
var fname = ""
with (document){
var number = getElementById("val4").value
var result = number.match(/[^0-9]/g)
if ((result != null && result.length > 0) || (number == "0")){
alert("Non-numeric or null character(s) found in Number\n" + result +
"\nPlease re-enter")
getElementById("val4").value=""
return
} // end if
else
number*=1

if (number==""){
fname = 'file'
+ getElementById("val3").value
+ getElementById("val2").value
+ getElementById("val1").value
+ '.html'
} // end if
else{
var from_first = (now - firstdate)/(24*60*60*1000) + 1
if (number > from_first) {
alert('Number=' + number + '\nNot in range 1 to ' + from_first +
"\nPlease re-enter")
getElementById("val4").value=""
return
} // end if

var newdate = new Date()
newdate.setFullYear(firstdate.getFullYear(),firstdate.getMonth(),firstdate.getDate()
+ number - 1)
var newyear = newdate.getFullYear()
var newmonth = newdate.getMonth() + 1
newmonth = (newmonth < 10) ? '0' + newmonth : newmonth
var newday = newdate.getDate()
newday = (newday < 10) ? '0' + newday : newday
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 not found, please press the Back
button'))
location.href = fname
else
getElementById("loadmsg").innerHTML = 'Load of ' + fname + '
cancelled'

getElementById("val4").value = ""
} // end with
} // end function
</script>
 
A

Alven

I paste your last version then when I run it under IE7
in the place Number I entered 1 and in the root directory on my server I
added a file (file20071126.html)
the error is
Line: 99
Char: 1
Error: Object expected
Code:0
URL: http://www.mysite.com/test.htm
test.htm is the file which is contain your code.


Trevor Lawrence said:
Alven said:
Thanks a lot Trevor for your help. Itried the code but it gave me error
regarding this line
<input type="button" value="Get File" onclick="loadfile()" />
So please advise
Thanks in advance

Alven,
Most odd.

I have been working on the code
a) for interest, and
b) in case you decide it is what you want. (If not, I can make changes)

I have had errors along the way, which I have corrected. But not this one

1. Can you post the text of the error, please
2. I am wondering whether the script is OK in the <head> section.

Here is my latest version of the script. It checks for a non-numeric in
Number as well as Number NOT between 26Nov and current date. (It does not
as yet check that any date entered in the Day, Month, Year boxes is in the
same range - I should do that also)

It returns no script errors using IE7

<script type ="text/javascript">
var now = new Date() ,
firstdate = new Date()
firstdate.setFullYear(2007,10,26)

function init(){
var yearno = now.getYear() ,
monthno = now.getMonth() + 1 ,
dateno = now.getDate()

with (document){
getElementById("val1").value = (dateno < 10) ? '0' + dateno : dateno
getElementById("val2").value = (monthno < 10) ? '0' + monthno :
monthno
getElementById("val3").value = yearno
getElementById("val4").value=""
}
}
function loadfile(){
var fname = ""
with (document){
var number = getElementById("val4").value
var result = number.match(/[^0-9]/g)
if ((result != null && result.length > 0) || (number == "0")){
alert("Non-numeric or null character(s) found in Number\n" + result +
"\nPlease re-enter")
getElementById("val4").value=""
return
} // end if
else
number*=1

if (number==""){
fname = 'file'
+ getElementById("val3").value
+ getElementById("val2").value
+ getElementById("val1").value
+ '.html'
} // end if
else{
var from_first = (now - firstdate)/(24*60*60*1000) + 1
if (number > from_first) {
alert('Number=' + number + '\nNot in range 1 to ' + from_first +
"\nPlease re-enter")
getElementById("val4").value=""
return
} // end if

var newdate = new Date()

newdate.setFullYear(firstdate.getFullYear(),firstdate.getMonth(),firstdate.getDate()
+ number - 1)
var newyear = newdate.getFullYear()
var newmonth = newdate.getMonth() + 1
newmonth = (newmonth < 10) ? '0' + newmonth : newmonth
var newday = newdate.getDate()
newday = (newday < 10) ? '0' + newday : newday
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 not found, please press the Back
button'))
location.href = fname
else
getElementById("loadmsg").innerHTML = 'Load of ' + fname + '
cancelled'

getElementById("val4").value = ""
} // end with
} // end function
</script>


--
Trevor Lawrence
Canberra
Microsoft MVP - FrontPage
MVP Web Site http://trevorl.mvps.org
 
T

Trevor Lawrence

Alven said:
I paste your last version then when I run it under IE7
in the place Number I entered 1 and in the root directory on my server I
added a file (file20071126.html)
the error is
Line: 99
Char: 1
Error: Object expected
Code:0
URL: http://www.mysite.com/test.htm
test.htm is the file which is contain your code.

Alven,

Thanks. What you have done looks OK. The files 'test.htm' and
'file20071126.html' should be on the same directory.

I often got "Error: Object expected" when I had made a small mistake in the
JS which resulted in the function not being recognised. It would be better
if the actual syntax error were described, because this error says very
little. (All it really says is: "The reference is to an object which doesn't
exist" - where I assume the object is "loadfile()" )

I think I need to see your actual site
http://www.mysite.com/test.htm is not a valid address. It gave this error:
404 Error -- File Not Found
The page you are looking for (http://mysite.com/test.htm) is not here

I have put up the code and a couple of files - file20071130.html and
file20071205.html
at http://tandcl.homemail.com.au/alven/daily.html

Either of these 2 will load (Number 5 or 10). Any other file will give a 404
File not found
 
A

Alven

Thanks it works I took daily.html and used it so the file is working fine
now
but I have a question if the counter now is 1126 for the index.htm date
11-12-2007 how we can tune starting from this counter on the other hand I
need when I enter this counter 1126 in the number cell it load this file
date 11-12-2007 then tomorrow the counter will be 1127 so it loads the file
date 12-12-2007 and so on. Can we do it?
Thanks in advance
 
T

Trevor Lawrence

Alven said:
Thanks it works I took daily.html and used it so the file is working fine
now
but I have a question if the counter now is 1126 for the index.htm date
11-12-2007 how we can tune starting from this counter on the other hand I
need when I enter this counter 1126 in the number cell it load this file
date 11-12-2007 then tomorrow the counter will be 1127 so it loads the
file date 12-12-2007 and so on. Can we do it?
Thanks in advance

Alven,
I am finding it difficult to understand the question

There are two parts to the date question
1. Date - in 3 parts
2. Number

The date part, as it is now, will take any input and use it to setup a file
reference
So Day=26 and Month=11 and Year= 2007 will set up a reference to file
'20071126.html'. If the file does not exist, the standard "File not found"
message will display. I have not set up any check on the validity of the
dates, or to check that it is in any range.

The number part accepts a number in the range 1 to xx, where xx is the
number of days from 26Nov2007 to the current date (counting both ends).
Anything else is rejected.

I chose the start date of 26Nov2007 because, in one post, you said today
should be file number 10 and I counted back from this to get the start date.
This start date is set at the top of the code and can easily be varied.

It now reads:
firstdate.setFullYear(2007,10,26)
Any date can be set here. Just remember to subtract one from the month
number (i.e. the 10 parameter here means month 11)

But I think you want to set a default date of today. This is already done in
the date part, so all that is needed to load today's file is to press the
button "Get File"

I hope that this helps. If not, please explain precisely what your
requirements are and I will try to work to it
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top