By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,481 Members | 3,170 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,481 IT Pros & Developers. It's quick & easy.

some sort of counter

P: n/a
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
Share this Question
Share on Google+
2 Replies


P: n/a
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

P: n/a

"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 discussion thread is closed

Replies have been disabled for this discussion.