some sort of counter

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • phoenix

    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


  • Yep

    #2
    Re: some sort of counter

    "phoenix" <me@privacy.net > wrote in message news:<3f92b5cb$ 0$3666$ba620e4c @reader2.news.s kynet.be>...
    [color=blue]
    > 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.[/color]

    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.onclic k = 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="retur n confirm(this.el ements['myCounter'].value||0)">
    <input type="hidden" name="myCounter " value="0">
    <input type="submit">
    </form>

    Comment

    • phoenix

      #3
      Re: some sort of counter


      "Yep" <y-e.perio@em-lyon.com> schreef in bericht
      news:d2d855ea.0 310191307.633b8 f74@posting.goo gle.com...[color=blue]
      > "phoenix" <me@privacy.net > wrote in message[/color]
      news:<3f92b5cb$ 0$3666$ba620e4c @reader2.news.s kynet.be>...[color=blue]
      >[color=green]
      > > Suppose I have a page with a set of hyperlinks on it. Each time a[/color][/color]
      hyperlink[color=blue][color=green]
      > > is clicked a new window is opened. What i basically want is the[/color][/color]
      following :[color=blue][color=green]
      > > 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.[/color]
      >
      > 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.onclic k = 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="retur n confirm(this.el ements['myCounter'].value||0)">
      > <input type="hidden" name="myCounter " value="0">
      > <input type="submit">
      > </form>[/color]

      thanks alot

      Yves


      Comment

      Working...