...

View Full Version : DIV Show/hide scrolls pages to top + fetch data only once problem



uandme72
11-25-2008, 06:31 AM
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.

rnd me
11-25-2008, 08:13 AM
replace your links with buttons and your problems will go away.

links go somewhere. buttons do something.

uandme72
11-25-2008, 09:23 AM
my page design does not permit me to use buttons instead of links.
kindly help.

rnd me
11-25-2008, 02:06 PM
well i guess you can say "return false;" as the last line of your onclick event...

EDIT: considering goal #2 as well:


<a href="#" onclick="alert('first time click'); this.onclick=function(){return false;}; return false;">one-time link</a>

abduraooft
11-25-2008, 02:19 PM
EDIT: considering goal #2 as well:


<a href="#" onclick="alert('first time click'); this.onclick=function(){return false;}; return false;">one-time link</a>
Too complex?

<a href="#" onclick="alert('first time click'); return false;">one-time link</a>

rnd me
11-25-2008, 02:30 PM
Too complex?

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

uandme72
11-28-2008, 04:00 AM
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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum