...

View Full Version : Javascript scroll check.. help



Timwork
05-03-2006, 04:26 PM
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?:confused:

Davide Zanotti
05-03-2006, 05:27 PM
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
05-03-2006, 05:50 PM
Yes, it works but you have to subtract the height of the div from the scrollHeight. :thumbsup:

Follow this quick example:



<!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>

Timwork
05-03-2006, 10:28 PM
Great (:

i've made a button with the id "button"

<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
05-09-2006, 10:42 PM
anyone?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum