read only text area or alternative

I have a site where there are conditions in a text area. I have set the text area to read only but noticed when you press the backspace it then takes you to the previous page.

Is there a way to prevent this (non js if possible) or maybe an alternative to textarea? kinda like the box I'm typing in right now but read only.
LVL 1
ShawnAsked:
Who is Participating?
 
LZ1Connect With a Mentor Commented:
I got this code from here: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_20276433.html 


Try this:
<script>
function checkShortcut()
{
                  if(event.keyCode==8 || event.keyCode==13)
         {
               return false;
         }
}
 </script>
<body onkeydown="return checkShortcut()">

Open in new window

0
 
LZ1Commented:
You could just put the content in a div, give it a width and height and then add overflow: visible which will allow it to scroll.  
0
 
ShawnAuthor Commented:
sounds good. do you have a quick example. never done that before and I'm not too hot with borders in css.
0
What Kind of Coding Program is Right for You?

There are many ways to learn to code these days. From coding bootcamps like Flatiron School to online courses to totally free beginner resources. The best way to learn to code depends on many factors, but the most important one is you. See what course is best for you.

 
LZ1Commented:
Something like this would work:


CSS

	#textArea {
		width:500px; /*Change to suit your needs */
		height:250px;/*Change to suit your needs */
		clear:both;
		border:1px inset #333;
		}

Open in new window

HTML: 

<div id="textArea">
Your content here 
</div>

Open in new window

0
 
ShawnAuthor Commented:
I get the box and text but the text goes out of the box rather then having the side bar appear.
0
 
LZ1Commented:
Add overflow:scroll;
0
 
ShawnAuthor Commented:
ok, I have the box looking nice now but I still have the same backspace behavior.
0
 
LZ1Commented:
Unfortunately the only way to completely disable the backspace key would be Javascript.  It's a default function of the browser itself, as far as I understand it.  
0
 
ShawnAuthor Commented:
i suppose I could use js. At least it could change that function. any ideas?
0
 
ShawnAuthor Commented:
it all works perfect now. thank you
0
 
LZ1Commented:
Glad I could help!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.