473,421 Members | 1,525 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,421 software developers and data experts.

js code execution causes scrolling back to top?

Hi-

I need to use self.scrollTo(x,y) as the last action in a js function called
by a onClick event. It seems that the scrolling actually takes place, but
the document is then scrolling back to top when js code execution has ended.

In the following example I get this effect in IE6 with the third and fourth
calls, while the first two work fine.

-------------------------------------------------------------
<HTML><HEAD><TITLE>scrollTo</TITLE>
<script language="JavaScript" type="text/JavaScript">
<!--
function scrollit(s) { self.scrollTo(0,s) }
-->
</script>
</HEAD>
<BODY>
<FORM name=myForm><INPUT onclick=self.scrollTo(0,300) type=button
value=scroll_(works_fine)> </FORM>
<p onClick="self.scrollTo(0,300)">scroll with event in paragraph
(works_fine)</p>
<p><a href="#" onClick="self.scrollTo(0,300)">scroll on event onclick in
anchor (doesn't work)</a></p>
<p><a href="#" onClick="scrollit(300)">scroll on event onclick in anchor,
calling a js function (doesn't work)</a></p>
<p>1</p><p>2</p><p>3</p><p>4</p><p>5</p><p>6</p><p>7</p><p>8</p><p>9</p><p>1
0</p>
<p>11</p><p>12</p><p>13</p><p>14</p><p>15</p><p>16</p><p>17</p><p>18</p>
</BODY></HTML>
----------------------------------------------------------------------------
----------------------------------

Any help highly appreciated

peppeprof
Jul 23 '05 #1
4 2474
peppeprof wrote:
Hi-
<p><a href="#" onClick="self.scrollTo(0,300)">scroll on event onclick in
anchor (doesn't work)</a></p>


Yes it does, it just then immediately follows the href (#) which
navigates to the top of the page.

<a href="#" onclick="self.scrollTo(0,300);return false">Now it will
work, but why are you using js to do what a link can do?</a>

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/
Jul 23 '05 #2
Ivo
"Randy Webb" asked

<a href="#" onclick="self.scrollTo(0,300);return false">Now it will
work, but why are you using js to do what a link can do?</a>


The way of the # would add to the window's history list. scrollTo has no
such effect.

Also, some find it better to use a totally empty href instead of the hash
for these onclick links. I don't remember the reason, but neither do I know
why the hash is there. Another, afaik equally workable idea is

<a href="javascript:void(' Descriptive statusbar message ')" onclick="...">

Buttons can be styled to look like links, and vice versa. Which are
generally to be preferred and why? Am I right in thinking links are easier
to render for a browser (both visually and in the DOM), that buttons take up
more resources?
Ivo
Jul 23 '05 #3
Lee
Ivo said:

"Randy Webb" asked

<a href="#" onclick="self.scrollTo(0,300);return false">Now it will
work, but why are you using js to do what a link can do?</a>
The way of the # would add to the window's history list. scrollTo has no
such effect.

Also, some find it better to use a totally empty href instead of the hash
for these onclick links. I don't remember the reason, but neither do I know
why the hash is there.


Some older browsers required that the value be a valid URL.
"#" is a valid URL. "" is not (or at least wasn't recognized as one)
Another, afaik equally workable idea is
<a href="javascript:void(' Descriptive statusbar message ')" onclick="...">


This method causes unpredictable results if Javascript is
not enabled.

Jul 23 '05 #4
> > <p><a href="#" onClick="self.scrollTo(0,300)">scroll on event onclick in
anchor (doesn't work)</a></p>
Yes it does, it just then immediately follows the href (#) which
navigates to the top of the page.

<a href="#" onclick="self.scrollTo(0,300);return false">Now it will
work, but why are you using js to do what a link can do?</a>
Randy


Thanks a lot! I've been really stupid...
but why are you using js to do what a link can do?</a>
Randy


'cause I have a vertical Iframe with many img links, scroll enabled; on
click event I want to address a html document in another Iframe, turn
visible some layers and hidden some others and, finally, make the menu
scroll to have the selected img in vertical middle. If this was to be on the
internet I would have probably used php, but this is gonna be a cd.

Thank you again

peppeprof
Jul 23 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: headware | last post by:
I have a <select> control that contains many entries. It allows the user to multi-select a group of them, click a button, and store the selected data in a database. Normally they do this starting...
1
by: Daveyk0 | last post by:
Hello there, I have a front end database that I have recently made very many changes to to allow off-line use. I keep copies of the databases on my hard drive and link to them rather than the...
5
by: MLH | last post by:
Having identified a A97 bug in which acDialog causes undesirable side effects processing the opened form, I would like to replace the following code running in MyForm ... DoCmd.OpenForm...
11
by: Peter Steele | last post by:
I have a Windows application written in C# that I want to return a non-zero exit code when it it run. The problem is that as a Windows application, there doesn't seem to be a way to control this....
2
by: John | last post by:
Hi, I have a web form accounting app. In certain instances it causes trouble if the user clicks the Back button. I've read several posts that indicate that it is not recommended (or even...
4
by: James Radke | last post by:
Hello, I am attempting to use the proper Try/Catch technique when accessing my Microsoft SQL server database and have a question... If I use something similar to the following: Try set up...
27
by: David Golightly | last post by:
This is just a quick poll for all you web devs out there: What browsers do you test on/are concerned about compatibility with? Obviously, you're going to test on current-generation browsers such...
3
by: vijay.db | last post by:
Hi Group, Running DB2 V8.2 Fxpack 9 in AIX 5.2, I get the following error frequently and my instance is stopped...collected some info like: the signal received is 11 which is SEGMENTATION...
1
by: jonceramic | last post by:
Hi All, I've noticed that in a lot of my forms and tables, when I'm on continuous view, I can't scroll when the focus is in a field or on a control. Meaning, if I have a list, and start...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.