WelcomeServicesPortfolioKnowledge BaseContact Us
27 Seconds, Inc.


Knowledge base View Article

need hosting?

Need hosting? We use and love our host - CrystalTech.com!
Need hosting? We use and love our host - CrystalTech.com!

Text Disguise - CAPTCHA-image/Human Interactive Proof web services

National Holiday Dates and Bank Holiday Dates - web site that provides the dates of national and bank holidays for the United States, United Kingdom, Ireland and Scotland

Holiday Web Service - web services for programmers to provide the dates of national and bank holidays in their applications for the United States, United Kingdom, Ireland and Scotland

Our Family Heart - web site to help families communicate no matter where they are

What?! You haven't heard about the greatest remote controlled flyer to come out in years?! Checkout the FlyTech DragonFly now!

Force a user to scroll to the end of a textarea.

Summary: During your form validation, you can force the user to scroll to the end of a textarea to ensure that they have had a chance to review all of the text contained within it.
 
Keywords: AGREE
FORM
SCROLL
VALIDATION
Applicable Software: Active Server Pages (ASP)
Active Server Pages .NET (ASP.NET)
DHTML
HTML
Internet Explorer
JavaScript
Netscape Navigator
 
Body:

There are instances where you want to force a user to view an entire piece of text. The particular instance that comes to mind is in the case of License Agreements. You want to be sure that the user has, at least, scrolled through the entire agreement before allowing them to proceed.

function textareaAtEnd(textareaObj)
{
	return ((textareaObj.scrollTop + textareaObj.offsetHeight) > textareaObj.scrollHeight);
}

To use it, you would do:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
	<title>Scroll Test</title>
	<script language="JavaScript">
	<!--
	
	function textareaAtEnd(textareaObj)
	{
		return ((textareaObj.scrollTop + textareaObj.offsetHeight) > textareaObj.scrollHeight);
	}

	function formValidation(formObj)
	{
		if (textareaAtEnd(formObj.licenseAgreement))
		{
			return true;
		}
		else
		{
			alert ("Please scroll to the end of the license agreement.")
			return false;
		}
	}

	// -->
	</script>
</head>

<body>

<form action="javascript: alert('Form submitted!');" onSubmit="return formValidation(this);">

	<p>
	License Agreement:<br />
	<textarea name="licenseAgreement" rows="10" cols="45">This is my long, long license agreement where you agree to all of my demands.
	
	This is my long, long license agreement where you agree to all of my demands.
	
	This is my long, long license agreement where you agree to all of my demands.
	
	This is my long, long license agreement where you agree to all of my demands.
	
	This is my long, long license agreement where you agree to all of my demands.
	
	This is my long, long license agreement where you agree to all of my demands.
	
	This is my long, long license agreement where you agree to all of my demands.
	
	This is my long, long license agreement where you agree to all of my demands.
	
	This is my long, long license agreement where you agree to all of my demands.
	
	This is my long, long license agreement where you agree to all of my demands.
	
	This is my long, long license agreement where you agree to all of my demands.
	
	This is my long, long license agreement where you agree to all of my demands.
	
	This is my long, long license agreement where you agree to all of my demands.
	
	This is my long, long license agreement where you agree to all of my demands.
	
	This is my long, long license agreement where you agree to all of my demands.
	
	This is my long, long license agreement where you agree to all of my demands.
	
	This is my long, long license agreement where you agree to all of my demands.
	
	This is my long, long license agreement where you agree to all of my demands.
	
	This is my long, long license agreement where you agree to all of my demands.</textarea>
	</p>

	<p>
	<input type="submit" value="Submit">
	</p>

</form>

</body>
</html>

 
Author: Douglas L. Setzer, II, http://www.27seconds.com
Posted On: 12/30/2003 6:41:09 AM

Rate this article: Average: 8
n/a12345678910
Comments?

Article Search   |   All Articles