Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Dec 2006
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation Javascript needed help needed

    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
    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
    So can anyone help me with a JavaScript to prevent this action?

  • #2
    New Coder TripperTreats's Avatar
    Join Date
    Oct 2006
    Posts
    92
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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>
    Psychedelic digital art at www.trippertreats.com.

    "And in the end, the love you take
    is equal to the love you make
    ."

  • #3
    Senior Coder nikkiH's Avatar
    Join Date
    Jun 2005
    Location
    Near Chicago, IL, USA
    Posts
    1,973
    Thanks
    1
    Thanked 32 Times in 31 Posts
    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.

    If this post contains any code, I may or may not have tested it. It's probably just example code, so no getting knickers in a bunch over a typo, OK? If it doesn't have basic error checking in it, such as object detection or checking if objects are null before using them, put that in there. I'm giving examples, not typing up your whole app for you. You run code at your own risk.
    Bored? Visit
    http://www.kaelisspace.com/

  • #4
    Regular Coder
    Join Date
    Sep 2005
    Posts
    535
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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...
    If you want answers, write a smart question.

    Yes, someone probably does know how...

    Oh, and if you want to learn, STFW!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •