/    Sign up×
Community /Pin to ProfileBookmark

I have a page that has links to add items to a shopping list. The problem I have is that when I click the link/img to add items to the shopping list, it takes me to the top of the page (if I have scrolled down to see items). Is it possible to not go back tot he top of the page when clicking the link? Here is the code I have:

[code]
<a title=”Add to shopping list” onclick=”Item(‘T09284~1060’,this.id)” href=”#” id=”datatblCircularItems:17:lnkAddShopList”>
<img title=”/images/btn_add_shopping_list.png” src=”/images/btn_add_shopping_list.png” id=”datatblCircularItems:17:txtoutAddToShopList”>
</a>
[/code]

Thanks!!

to post a comment
JavaScript

10 Comments(s)

Copy linkTweet thisAlerts:
@netbuddyJun 22.2006 — change the href element to href="javascript:;" and that should do the trick with the page not reloading, what happens is the # is saying to look for somethng but no anchor is named so the page defaults to top.
Copy linkTweet thisAlerts:
@jrthor2authorJun 22.2006 — thanks, that worked great. Now, 1 more question. On my shopping list page, I have a link to remove items, which reloads the page to show the page with the item removed. Is there a way to also not go to the top of the page when the page reloads? Here is the code:
<i>
</i>&lt;a title="Remove from shopping list" onclick="javascript: removeItem('T14789~1060')" href="/shopList.jsf?circularId=1060&amp;region=east&amp;val=1327012914" id="tblShoppingList:2:lnkRemoveFromShopList"&gt;
&lt;img width="167" height="17" title="Remove from shopping list" alt="Remove from shopping list" src="/images/btn_remove_shopping_list.png" id="tblShoppingList:2:removeShopList"&gt;

Thanks again.
Copy linkTweet thisAlerts:
@netbuddyJun 22.2006 — if you have an anchor 'name' attribute set on the next page, a href='whateverthenextpageis.html#gototheanchornamed' should do that for you.

if the item is in the same page, the urls can simply be href='#gototheanchornamed'
Copy linkTweet thisAlerts:
@jrthor2authorJun 22.2006 — this is the same page, but I don't have any anchor names. What would the anchor name be though. If I am at the bottom of my page, I click the remove item link, I want the item removed from the page, but not scrolled to the top, just keep the page where it is.
Copy linkTweet thisAlerts:
@netbuddyJun 22.2006 — the anchor name can be whatever you want (witin reason)

example...

<a name='myAnchor'></a>

will be referenced as #myAnchor in the URL

so now if you have a link in the page with a href='#myAnchor', the page will scroll to that anchor position.
Copy linkTweet thisAlerts:
@jrthor2authorJun 22.2006 — but that anchor name '#myAnchor' referenced in the href would have to be the anchor name for the product right above the one I want removed, right?
Copy linkTweet thisAlerts:
@netbuddyJun 22.2006 — you would need to use an anchor per item and the anchor would need to be placed 'ABOVE' the scroll point as you figured out and also unique naming applies.

if you had <a name='someAnchorName></a><hr><img id='imageId' ...

the anchor point would exist left of or above the horizontal rule.
Copy linkTweet thisAlerts:
@jrthor2authorJun 22.2006 — so how would I point my href to the anchor tag to the one before it?
Copy linkTweet thisAlerts:
@netbuddyJun 22.2006 — grab the document.anchors and loop through it, find the 'name' property reference you want and then you know which one is in the loop, pick the previous anchor in the collection.
Copy linkTweet thisAlerts:
@jrthor2authorJun 22.2006 — got any code examples that show how to do that?
×

Success!

Help @jrthor2 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...