{"id":123,"date":"2008-09-08T20:04:11","date_gmt":"2008-09-09T01:04:11","guid":{"rendered":"http:\/\/stein.everybody.org\/brain\/?p=123"},"modified":"2011-03-10T10:57:27","modified_gmt":"2011-03-10T15:57:27","slug":"javascript-on-scroll-to-end","status":"publish","type":"post","link":"https:\/\/jeremystein.com\/brain\/javascript-on-scroll-to-end\/","title":{"rendered":"Javascript: on scroll to end"},"content":{"rendered":"<p>Sometimes software installers force you to scroll to the end of the EULA before the &#8220;I agree&#8221; box is enabled.  If you want the same affect in HTML, you can use javascript like this:<\/p>\n<pre>&lt;html&gt;\n    &lt;head&gt;\n        &lt;script type=\"text\/javascript\"&gt;\n            function setupPage() {\n                var agreement = document.getElementById(\"agreetext\");\n                var visibleHeight = agreement.clientHeight;\n                var scrollableHeight = agreement.scrollHeight;\n                if (scrollableHeight &gt; visibleHeight) {\n                    var checkbox = document.getElementById(\"agreebox\");\n                    checkbox.checked=false;\n                    checkbox.disabled=true;\n                    agreement.onscroll = handleScroll;\n                }\n            }\n\n            function handleScroll() {\n                var agreement = document.getElementById(\"agreetext\");\n                var visibleHeight = agreement.clientHeight;\n                var scrollableHeight = agreement.scrollHeight;\n                var position = agreement.scrollTop;\n                if (position + visibleHeight == scrollableHeight) {\n                    document.getElementById(\"agreebox\").disabled=false;\n                }\n            }\n        &lt;\/script&gt;\n    &lt;\/head&gt;\n    &lt;body&gt;\n        &lt;form&gt;\n            &lt;textarea id=\"agreetext\" rows=\"8\" cols=\"40\" onscroll=\"calc();\"&gt;Long agreement&lt;\/textarea&gt;\n            &lt;br\/&gt;&lt;br\/&gt;\n            &lt;input type=\"checkbox\" id=\"agreebox\" value=\"true\"\/&gt; &lt;label id=\"agreelabel\" for=\"agreebox\"&gt;I agree&lt;\/label&gt;\n            &lt;br\/&gt;&lt;br\/&gt;\n            &lt;input type=\"submit\" value=\"Continue\"\/&gt;\n        &lt;\/form&gt;\n        &lt;script type=\"text\/javascript\"&gt;\n            \/\/ We put this at the end of the page rather than in an document.onload\n            \/\/ because the document.onload event doesn't fire until all images have loaded.\n            setupPage();\n        &lt;\/script&gt;\n    &lt;\/body&gt;\n&lt;\/html&gt;\n<\/pre>\n<p><a href=\"http:\/\/stein.everybody.org\/brain\/wp-content\/uploads\/2008\/09\/agree.html\">See it in action<\/a>.<\/p>\n<p><!--comment_first--><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Sometimes software installers force you to scroll to the end of the EULA before the &#8220;I agree&#8221; box is enabled. If you want the same affect in HTML, you can use javascript like this: &lt;html&gt; &lt;head&gt; &lt;script type=&#8221;text\/javascript&#8221;&gt; function setupPage() { var agreement = document.getElementById(&#8220;agreetext&#8221;); var visibleHeight = agreement.clientHeight; var scrollableHeight = agreement.scrollHeight; if (scrollableHeight [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[34],"tags":[],"class_list":["post-123","post","type-post","status-publish","format-standard","hentry","category-javascript"],"_links":{"self":[{"href":"https:\/\/jeremystein.com\/brain\/wp-json\/wp\/v2\/posts\/123","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jeremystein.com\/brain\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jeremystein.com\/brain\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jeremystein.com\/brain\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/jeremystein.com\/brain\/wp-json\/wp\/v2\/comments?post=123"}],"version-history":[{"count":0,"href":"https:\/\/jeremystein.com\/brain\/wp-json\/wp\/v2\/posts\/123\/revisions"}],"wp:attachment":[{"href":"https:\/\/jeremystein.com\/brain\/wp-json\/wp\/v2\/media?parent=123"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jeremystein.com\/brain\/wp-json\/wp\/v2\/categories?post=123"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jeremystein.com\/brain\/wp-json\/wp\/v2\/tags?post=123"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}