473,322 Members | 1,718 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

some sort of counter

Hi,

I wonder if the following is even possible :

Suppose I have a page with a set of hyperlinks on it. Each time a hyperlink
is clicked a new window is opened. What i basically want is the following :
I want a counter at the client side which increments each time the user
clicks one of those links. At the bottom of the page I'll put a button
which should be used to send the value of the counter away.

The problem is I only know server side scripting and have no idea on how to
implement such a counter on the client side. I even wonder if it's possible
to detect when a link is clicked. The links may be buttons if that would
make it easier, it's just that i don't want to reload the page each time a
link is clicked but only at the end when the button at the bottom would be
clicked.

All help is appreciated.

TIA

Yves
Jul 20 '05 #1
2 2165
Yep
"phoenix" <me@privacy.net> wrote in message news:<3f**********************@reader2.news.skynet .be>...
Suppose I have a page with a set of hyperlinks on it. Each time a hyperlink
is clicked a new window is opened. What i basically want is the following :
I want a counter at the client side which increments each time the user
clicks one of those links. At the bottom of the page I'll put a button
which should be used to send the value of the counter away.


What a strange requirement :-)

Since your links open a new window, I can assume that they have a
target attribute; you can therefore capture a click on the document
and study the event bubble path; if, while processing, you encounter a
link which has a non-empty target attribute, then just update a
counter somewhere.
<script type="text/javascript">
document.onclick = function (evt) {
evt = evt || window.event;
var node = evt && (evt.srcElement || evt.target);
if(node && node.nodeName && node.parentNode) {
while(node &&
!(node.nodeName.toLowerCase()=="a" && node.target)) {
node = node.parentNode;
}
if (node)
with (document.forms["myForm"].elements["myCounter"])
value = +value + 1;
}
}
</script>

<a href="a.html" target="a">A</a>
<a href="b.html" target="b">B</a>

<form action="foo"
name="myForm"
onsubmit="return confirm(this.elements['myCounter'].value||0)">
<input type="hidden" name="myCounter" value="0">
<input type="submit">
</form>
Jul 20 '05 #2

"Yep" <y-*******@em-lyon.com> schreef in bericht
news:d2**************************@posting.google.c om...
"phoenix" <me@privacy.net> wrote in message news:<3f**********************@reader2.news.skynet .be>...
Suppose I have a page with a set of hyperlinks on it. Each time a hyperlink is clicked a new window is opened. What i basically want is the following : I want a counter at the client side which increments each time the user
clicks one of those links. At the bottom of the page I'll put a button
which should be used to send the value of the counter away.


What a strange requirement :-)

Since your links open a new window, I can assume that they have a
target attribute; you can therefore capture a click on the document
and study the event bubble path; if, while processing, you encounter a
link which has a non-empty target attribute, then just update a
counter somewhere.
<script type="text/javascript">
document.onclick = function (evt) {
evt = evt || window.event;
var node = evt && (evt.srcElement || evt.target);
if(node && node.nodeName && node.parentNode) {
while(node &&
!(node.nodeName.toLowerCase()=="a" && node.target)) {
node = node.parentNode;
}
if (node)
with (document.forms["myForm"].elements["myCounter"])
value = +value + 1;
}
}
</script>

<a href="a.html" target="a">A</a>
<a href="b.html" target="b">B</a>

<form action="foo"
name="myForm"
onsubmit="return confirm(this.elements['myCounter'].value||0)">
<input type="hidden" name="myCounter" value="0">
<input type="submit">
</form>


thanks alot

Yves
Jul 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: GujuBoy | last post by:
Hello All, I am farely new at PHP....I am looking for a ReDirection script with maybe the following features I need to have a "top" banner on my site with circulating banner ads so that it...
15
by: chahnaz.ourzikene | last post by:
Hi all, This is the first i post in this newsgroup, i hope my english is not too bad... Let's get straight to the point ! I have a little probleme using threads in my little training example :...
3
by: Kevin King | last post by:
I have a question about an assignment I have. I need to count the number of comparisons in my merge sort. I know that the function is roughly nlog(n), but I am definately coming up with too many...
193
by: Michael B. | last post by:
I was just thinking about this, specifically wondering if there's any features that the C specification currently lacks, and which may be included in some future standardization. Of course, I...
8
by: bmlclemson08 | last post by:
Hey if anyone could I need to find out how to write a program that will read in any number of integers, including none, and determine which is the largest integer. The part i can't figure out is...
0
by: Henkie | last post by:
Hello all, I have the following that I can not getting work, for example my input file is as below Test01,Bitmap01,01 Test02,Bitmap02,02 Test04,Bitmap04,04 Test05,Bitmap05,05...
17
by: rhitz1218 | last post by:
Hi, I'm trying to create a function that will sort a number's digits from highest to lowest. For example 1000 - will become 0001 or 1234 to 4321
3
by: biddy2 | last post by:
Hi all I am trying to wirte a program to sort an arry of size 10 into ascending order. I also need to ensure that after the second pass it only makes eight comparisons , seven compairisions on the...
51
by: Ojas | last post by:
Hi!, I just out of curiosity want to know how top detect the client side application under which the script is getting run. I mean to ask the how to know whether the script is running under...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.