View Full Version : Stop page from scrolling on an onclick
01-21-2009, 01:12 PM
<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?
01-21-2009, 01:46 PM
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).
01-21-2009, 05:11 PM
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).
Powered by vBulletin® Version 4.2.2 Copyright © 2017 vBulletin Solutions, Inc. All rights reserved.