Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 05-03-2006, 03:26 PM   PM User | #1
Timwork
New to the CF scene

 
Join Date: May 2006
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Timwork is an unknown quantity at this point
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?
Timwork is offline   Reply With Quote
Old 05-03-2006, 04:27 PM   PM User | #2
Davide Zanotti
New Coder

 
Join Date: Feb 2006
Location: Italy
Posts: 51
Thanks: 0
Thanked 0 Times in 0 Posts
Davide Zanotti is an unknown quantity at this point
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
}
Davide Zanotti is offline   Reply With Quote
Old 05-03-2006, 04:50 PM   PM User | #3
Davide Zanotti
New Coder

 
Join Date: Feb 2006
Location: Italy
Posts: 51
Thanks: 0
Thanked 0 Times in 0 Posts
Davide Zanotti is an unknown quantity at this point
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>
Davide Zanotti is offline   Reply With Quote
Old 05-03-2006, 09:28 PM   PM User | #4
Timwork
New to the CF scene

 
Join Date: May 2006
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Timwork is an unknown quantity at this point
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?
Timwork is offline   Reply With Quote
Old 05-09-2006, 09:42 PM   PM User | #5
Timwork
New to the CF scene

 
Join Date: May 2006
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Timwork is an unknown quantity at this point
anyone?
Timwork is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 04:01 AM.


Advertisement
Log in to turn off these ads.