Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

a href="#" moves my page scroll to the top

Status
Not open for further replies.

stefes007

Programmer
Apr 24, 2001
21
0
0
BE
I have a HTML page with form to fill.
Under those fields, there are images which fill automatically some fields when we clic on it.
Here is the code:
<a href=&quot;#&quot; onClick=&quot;recopiecoltab(0)&quot;>
<IMG SRC=&quot;nexts.gif&quot; border=0></a>

When I clic on that image the page scroll goes up to the top.
Is it possible to avoid that scroll?

Thanks for your help.





Dekeyzer Stephane.
Belgium :)
 
Instead of calling the javascript function in the onclick event, call it in href.

<a href=&quot;javascript:recopiecoltab(0)&quot;><IMG SRC=&quot;nexts.gif&quot; border=0></a>.

This will solve ur problem.
 
The solution is simple: add &quot;return false&quot; to the function call:

<a href=&quot;#&quot; onClick=&quot;recopiecoltab(0); return false&quot;>
 
Another way to do it is the following :
Code:
<IMG SRC=&quot;nexts.gif&quot; border=0 onClick=&quot;recopiecoltab(0)&quot;>
note that, with this typing, your image is not diplayed as a link and no normal link styling is applied to it. Water is not bad as soon as it stays out human body ;-)
 
Events of Image object like <img onclick=&quot;&quot;> are not supported by NN4 and therefore not recommended to use.
 
sorry, I didn't know. Water is not bad as soon as it stays out human body ;-)
 
thanks a lot,

i finally choose that solution:

<IMG SRC=&quot;nexts.gif&quot; border=0 onClick=&quot;recopiecoltab(0)&quot;>

it works perfectly. Dekeyzer Stephane.
Belgium :)
 
Starway: what about
<a href=&quot;#&quot; onClick=window.open(&quot;new.htm&quot;,&quot;name&quot;,&quot;width=300,height=300&quot;)><img border=&quot;0&quot; src=&quot;print.gif&quot;></a>
is it also not allowed for NN4?
 
smarties,
To tell you the truth, I never tried to call window.open() on link onclick event, and don't even want to try.
I always do it from JS function determined in the <head> of the document.

Using standard techniques and rules help you to avoid many troubles and save time you may waste on useless bug hunting. I better strict to other, more important things.
 
starway does have a point, but I rather stick to better things than NN4 anyways where I know things will work and not have unexplained bugs! :) Gary Haran
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top