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 5 of 5
  1. #1
    New to the CF scene
    Join Date
    May 2006
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Javascript scroll check.. help

    Hey all..
    im quite new here.. (actually this is my first post)

    im trying to figure out how to make a javascript function that checks if in example a set of rules before registrering are scrolled down to the bottom of the text field so that the submit button is disabled untill the rules box are scrolled down..
    can someone help me?

  • #2
    New Coder
    Join Date
    Feb 2006
    Location
    Italy
    Posts
    51
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I haven't tried but, I think you can use something like this:

    var element = document.getElementById(id);

    if(element.scrollTop==element.scrollHeight){
    // enable my button
    }

  • #3
    New Coder
    Join Date
    Feb 2006
    Location
    Italy
    Posts
    51
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Yes, it works but you have to subtract the height of the div from the scrollHeight.

    Follow this quick example:

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <title>Untitled Document</title>
    
    	<script type="text/javascript">
    		function foo(){
    			if(document.getElementById('x').scrollTop==(document.getElementById('x').scrollHeight-parseInt(document.getElementById('x').style.height))){
    				alert('yes!');
    			} else {
    				alert('no!');
    			}
    		}
    	</script>
    </head>
    
    <body>
    
    
    	<div id="x" style="width: 160px; height: 80px; overflow:auto; padding:0; margin:0">
    		asdfsdfsdfasdfasdf<br />
    		asdfsdfsdfa sdfasdfasd fsdfsdfasdfasdf<br />
    		asdfsdfsdfasdfasdf<br />
    		asdfsdfsdfasdfasdf<br />
    		asdfsdfsdfasdfasdf<br />
    		asdfsdfsdfasdfasdf<br />
    		asdfsdfsdfasdfasdf<br />
    		asdfsdfsdfasdfasdf<br />
    		asdfsdfsdfasdfasdf<br />
    	</div>
    
    <input type="button" onclick="foo()" value="test" />
    
    </body>
    
    </html>

  • #4
    New to the CF scene
    Join Date
    May 2006
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation

    Great (:

    i've made a button with the id "button"
    Code:
    <form name="agree">
    <input type="button" id="button" disabled=no value="test" />
    </form>
    what i need to do is when the document is not scrolled down the button will be disabled and when the user scrolls down it is re-enabled

    can this be done?

  • #5
    New to the CF scene
    Join Date
    May 2006
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    anyone?


  •  

    Posting Permissions

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