ARTLUNG LAB Share

Originally written 8/12/2000 for MSIE 4; Updated October 2002 for Mozilla/Netscape/MSIE/Opera

Changing the color of a form element when it's blank

The idea is that you give the user feedback when they're missing something


HTML Source Code

<form action="../"> <textarea rows="4" cols="40" onclick="checkPink(this)" onfocus="checkPink(this)" onblur="checkPink(this)" onchange="checkPink(this)">Delete this copy to make this pink</textarea> <input size="30" onclick="checkPink(this)" onfocus="checkPink(this)" onblur="checkPink(this)" onchange="checkPink(this)" value="Delete this copy to make this pink"> </form>

Source Code

<script language="JavaScript" type="text/javascript">
<!--
function checkPink(obj) {
	if (obj.value=='') {
		if ((document.all)||(document.getElementById)) {
			obj.style.backgroundColor = '#FF99CC';
		}
	} else {
		if ((document.all)||(document.getElementById)) {
			obj.style.backgroundColor = '#FFFFFF';
		}
	}
}
//-->
</script>