Prevent backspace for form, but allow for fields

This code prevents the user from using the backspace key to page back, but still allows it within text and textbox fields
JavaScript

JS Header

function preventbackspace() {
	//Only allow backspace for entry fields
	if (typeof window.event != 'undefined') {
	        	document.onkeydown = function() {
               	 		if (event.srcElement.tagName.toUpperCase() == 'INPUT' || event.srcElement.tagName.toUpperCase() == 'TEXTAREA'){
				/*allow*/
			}else {
               	         			return (event.keyCode != 8);
               			}
        		}
	} else {
        		document.onkeypress = function(e) {
                		if (e.target.nodeName.toUpperCase() == 'INPUT' || e.target.nodeName.toUpperCase() == 'TEXTAREA') {
				/*allow*/
			}else{
                        			return (e.keyCode != 8);
     			}
		}
	}
}

Insert the following call in the body onKeyDown event

preventbackspace();

Written by Frank Joseph Brefere III

Posted by fbrefere001 on Sunday November 18, 2007