View Full Version : Javascript needed help needed

Dec 29th, 2006, 04:07 PM
At my WebPages when I click at a button at the bottom of the page it takes my back automatically at the top of the page and some how I fell that it is annoying :eek:
the same thing when i click at any object at the center and an action should be taken the page when it reloads it takes me back at the top while it should take me to the center of the page where it took action :confused:
So can anyone help me with a JavaScript to prevent this action?

Dec 29th, 2006, 05:12 PM
This sounds like you need anchors. No javascript is required. If you want to stay in the center of the page after clicking something, you need to insert an anchor just above the button, as in

<a name="middleAnchor"> and on the button you put

<a href="#middleAnchor" onclick="doOtherStuff()"><button .......></a>

Dec 29th, 2006, 05:15 PM
If using a link to perform an action, return false onclick.

<a href="#" onclick="myfunction();return false;">

If using a button, you should not be seeing this behavior unless you called it a submit button. If you don't want a server roundtrip, why submit the form at all?
You can use a regular button instead.

Dec 29th, 2006, 07:01 PM
If you do need to go back to the server, you may consider using AJAX or some similar technique where the call back to the server is transparent to the user (meaning I can hit a button and the program control goes back to the server without the current page being refreshed and putting the view back to the top of the page). Note that this AJAX technique is a little more advanced topic, but there are a few good tutorials out on the web...