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 3 of 3
  1. #1
    Regular Coder
    Join Date
    Jan 2009
    Posts
    156
    Thanks
    47
    Thanked 0 Times in 0 Posts

    Stop page from scrolling on an onclick

    <input class='absmiddle' type='checkbox' name='chg' id='chg' onclick='toggle(this); return false;'>

    I thought the return false would prevent this but the page scrolls up a bit. What's wrong?

  • #2
    Regular Coder Common's Avatar
    Join Date
    Jan 2009
    Location
    Glasgow, UK
    Posts
    133
    Thanks
    16
    Thanked 13 Times in 13 Posts
    That just means that something's gone wrong somewhere, it could be in any of the lines above it, like a missed out tag or some conflicting javascript.
    Also, I doubt it's good practice to have your name and id as the same, so try changing that (although I dont think that would affect the onClick).

  • #3
    Senior Coder
    Join Date
    Oct 2008
    Location
    Long Beach
    Posts
    1,196
    Thanks
    36
    Thanked 164 Times in 164 Posts
    Show the toggle code, actually post all the relevant code on that page.

    return false doesn't do anything on <input type="button">s. You're probably thinking of anchors (in which case you're spot on).

    Also, I doubt it's good practice to have your name and id as the same
    - Best practice is to use ids where relevant and names where relevant. If your element requires both for some reason (can't think of a situation like this off the top of my head) then there is no problem assigning the same value to both, it actually makes sense. I see name and id having the same value most often when dealing with forms with outdated validation code (where the developer doesn't have access or the time to update the JS).
    Feel free to e-mail me if I forget to respond ;)
    ohsosexybrit@gmail.com


  •  

    Posting Permissions

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