I'm assigning readonly property to textbox in my page. I'm getting couple of issue. Even though the textbox is readonly, I can click on it (cursor blinks in the textbox) and then of I press backspace, it takes me to the previous page. I'm not suppose to
used enable property. Please advise.
Whuddayamean "No"? It was a statement of fact, not a question. And it is true. You clicked on the textbox which is readonly and thus not editable. Therefore the focus was not on any editable control so the browser went back one page in it's history as
per the design of the browser.
This is natural browser behaviour so either accept it or write your own browser.
If your job is riding on this you can try the old "onFocus=getRidOfTheFocus()" and set focus to an editable field that does nothing but that only irritates the users. It is better to educate the users than to try unfriendly hacks.
In the future if you want help on this forum try to be more informative than "No". Be sure to mark RemithR's post as the answer too.
Whuddayamean "No"? It was a statement of fact, not a question. And it is true. You clicked on the textbox which is readonly and thus not editable. Therefore the focus was not on any editable control so the browser went back one page in it's history as
per the design of the browser.
This is natural browser behaviour so either accept it or write your own browser.
If your job is riding on this you can try the old "onFocus=getRidOfTheFocus()" and set focus to an editable field that does nothing but that only irritates the users. It is better to educate the users than to try unfriendly hacks.
In the future if you want help on this forum try to be more informative than "No". Be sure to mark RemithR's post as the answer too.
Apologies... I read your email in a hurry (office leaving time) and thought as if as a question: if the same behavior occurs on editable textbox. Sorry dude. Next time I'll be more careful. Chill.
What a dumb arse reply. Natural behaviour - well if that's the case then browsers should have been still born. Which jesus-sandal wearing moron came up with this one.
Anyway here is my workaround to a very poor design...
<script type="text/javascript" language="javascript">
//========================================
// Disable Backspace key in IE and Firefox
//========================================
// Trap Backspace(8) except on text/textareas (unless they are read only)
document.onkeypress = function(event) {
if (typeof window.event != 'undefined') { // ie
event = window.event;
event.target = event.srcElement; // make ie confirm to standards !!
}
var kc = event.keyCode;
var tt = event.target.type;
if ((kc == 8)) {
if (tt == 'text' || tt == 'textarea') {
var readOnly = event.target.attributes.getNamedItem('readOnly');
if (readOnly != null) {
if (readOnly.value == 'true')
return false;
else
return true;
}
else
return true;
}
else
return false;
}
else
return true;
}
if (typeof window.event != 'undefined') // ie
document.onkeydown = document.onkeypress; // Trap bksp in ie.
smurtuza
Member
25 Points
88 Posts
BackSpace on ReadOnly Controls
Dec 30, 2009 08:26 PM|LINK
Hello All,
I'm assigning readonly property to textbox in my page. I'm getting couple of issue. Even though the textbox is readonly, I can click on it (cursor blinks in the textbox) and then of I press backspace, it takes me to the previous page. I'm not suppose to used enable property. Please advise.
Thanks.
RemithR
Contributor
2376 Points
396 Posts
Re: BackSpace on ReadOnly Controls
Dec 30, 2009 09:13 PM|LINK
if the cursor/focus is not on any editable controls and backspace is pressed it functions same as browser back button
smurtuza
Member
25 Points
88 Posts
Re: BackSpace on ReadOnly Controls
Dec 30, 2009 09:16 PM|LINK
kraznodar
Contributor
3333 Points
883 Posts
Re: BackSpace on ReadOnly Controls
Dec 30, 2009 09:47 PM|LINK
Whuddayamean "No"? It was a statement of fact, not a question. And it is true. You clicked on the textbox which is readonly and thus not editable. Therefore the focus was not on any editable control so the browser went back one page in it's history as per the design of the browser.
This is natural browser behaviour so either accept it or write your own browser.
If your job is riding on this you can try the old "onFocus=getRidOfTheFocus()" and set focus to an editable field that does nothing but that only irritates the users. It is better to educate the users than to try unfriendly hacks.
In the future if you want help on this forum try to be more informative than "No". Be sure to mark RemithR's post as the answer too.
smurtuza
Member
25 Points
88 Posts
Re: BackSpace on ReadOnly Controls
Dec 31, 2009 03:17 AM|LINK
alok_dida
Participant
1095 Points
314 Posts
Re: BackSpace on ReadOnly Controls
Dec 31, 2009 04:06 AM|LINK
Check it out following link..it will disable the backspace button
http://www.4guysfromrolla.com/webtech/111500-1.shtml
<input id="gwProxy" type="hidden"><input onclick="jsCall();" id="jsProxy" type="hidden">
<div id="refHTML"></div>masloan
Member
4 Points
2 Posts
Re: BackSpace on ReadOnly Controls
Oct 30, 2010 08:11 PM|LINK
What a dumb arse reply. Natural behaviour - well if that's the case then browsers should have been still born. Which jesus-sandal wearing moron came up with this one.
Anyway here is my workaround to a very poor design...
<script type="text/javascript" language="javascript">
//========================================
// Disable Backspace key in IE and Firefox
//========================================
// Trap Backspace(8) except on text/textareas (unless they are read only)
document.onkeypress = function(event) {
if (typeof window.event != 'undefined') { // ie
event = window.event;
event.target = event.srcElement; // make ie confirm to standards !!
}
var kc = event.keyCode;
var tt = event.target.type;
if ((kc == 8)) {
if (tt == 'text' || tt == 'textarea') {
var readOnly = event.target.attributes.getNamedItem('readOnly');
if (readOnly != null) {
if (readOnly.value == 'true')
return false;
else
return true;
}
else
return true;
}
else
return false;
}
else
return true;
}
if (typeof window.event != 'undefined') // ie
document.onkeydown = document.onkeypress; // Trap bksp in ie.
</script>