Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    New to the CF scene
    Join Date
    Nov 2008
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    DIV Show/hide scrolls pages to top + fetch data only once problem

    have a rather long page in which I would like to have certain DIVs show or hide by clicking on a link (one link per DIV). I am creating all the DIV dynamically using ASP database and populating the text inside DIV using AJAX which is triggered at onClick event of the link.

    I have two issues:
    1. I created the script, but the problem is that when I trigger the function from an onclick event from within a link, the page scrolls back to the top of the page. I would like to be able to trigger the onclick event without the page scrolling from it's current position in the browser window.

    I tried using the "#" in the href attribute, but that makes the page scroll to the top. I tried leaving off the href attribute, but then the link becomes an anchor and does not appear to the user as a link (the pointer does not become a hand and the link is not styled as a link). I even tried creating anchors to use in the href attribute, but that still scrolls the page. I would ideally like the browser window to not move at all.

    2. I dont want the AJX script to fetch the record everytime the link is clicked. The AJAX server script ASP page should be called only the first time the link is clicked.

    Please help.

  • #2
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,273
    Thanks
    10
    Thanked 581 Times in 562 Posts
    replace your links with buttons and your problems will go away.

    links go somewhere. buttons do something.
    my site (updated 13/9/26)
    BROWSER STATS [% share] (2014/5/28) IE7:0.1, IE8:5.3, IE11:8.4, IE9:3.2, IE10:3.2, FF:18.2, CH:46, SF:7.9, NON-MOUSE:32%

  • #3
    New to the CF scene
    Join Date
    Nov 2008
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    my page design does not permit me to use buttons instead of links.
    kindly help.

  • #4
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,273
    Thanks
    10
    Thanked 581 Times in 562 Posts
    well i guess you can say "return false;" as the last line of your onclick event...

    EDIT: considering goal #2 as well:
    Code:
    <a href="#" onclick="alert('first time click'); this.onclick=function(){return false;}; return false;">one-time link</a>
    Last edited by rnd me; 11-25-2008 at 01:09 PM.
    my site (updated 13/9/26)
    BROWSER STATS [% share] (2014/5/28) IE7:0.1, IE8:5.3, IE11:8.4, IE9:3.2, IE10:3.2, FF:18.2, CH:46, SF:7.9, NON-MOUSE:32%

  • #5
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,849
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    Quote Originally Posted by rnd me View Post
    EDIT: considering goal #2 as well:
    Code:
    <a href="#" onclick="alert('first time click'); this.onclick=function(){return false;}; return false;">one-time link</a>
    Too complex?
    Code:
    <a href="#" onclick="alert('first time click'); return false;">one-time link</a>
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #6
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,273
    Thanks
    10
    Thanked 581 Times in 562 Posts
    Quote Originally Posted by abduraooft View Post
    Too complex?
    Code:
    <a href="#" onclick="alert('first time click'); return false;">one-time link</a>
    uhh, that fires every time, not just the first like OP wanted...
    my site (updated 13/9/26)
    BROWSER STATS [% share] (2014/5/28) IE7:0.1, IE8:5.3, IE11:8.4, IE9:3.2, IE10:3.2, FF:18.2, CH:46, SF:7.9, NON-MOUSE:32%

  • #7
    New to the CF scene
    Join Date
    Nov 2008
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I dont want to stop click action second time.
    What I want is that on every click the div should become visible/invisible, but the ajax script should run only on the first click. the ajax script page which sends data should not run from second click onwards.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •