We help IT Professionals succeed at work.

Disable text field in IE as well as in Netscape.

vinayc25
vinayc25 asked
on
Hi Guys,

I want to disable a text field in IE as well as in Netscape.
I tried using "onFocus='this.blur()'" but this disables all the keyboard events in both IE and Netscape.So if I use the keyboard the text fields are disabled.

"
But still the value present in the text field can be selected by right clicking the mouse and can be deleted.
"

I tried using the code for disabling the right click of mouse and it works fine both in IE and Netscape ONLY for static text and as soon as I add a text field on the page this code stops working in Netscape.

So can someone provide me the code to disable the text field for both keyboard events and mouse events.

Its very urgent...

Thanks,
Vinay


Comment
Watch Question

<input type=text value="disabled"  disabled>

Commented:
Well this code works in Netscape 4.7, Netscape 6 and Internet Explorer:

<html>
<head>
</head>
<body>
<form>
<input type="text" name="myText" value="" onfocus="if(this.readonly){ this.blur(); }"<br>
<input type="button" value="disable textbox" onclick="this.form.myText.readonly = true;">
<input type="button" value="enable textbox" onclick="this.form.myText.readonly = false;">
</form>
</body>
</html>

:o)

Ant

Commented:
udnimbalkar, that will not work in Netscape 4.x

Ant

Commented:
still you can select/copy/paste into the textfield. to completely disable right-click on the document add,

<script language=JavaScript>
<!--
var message="";
function clickIE() {if (document.all) {(message);return false;}}
function clickNS(e) {if
(document.layers||(document.getElementById&&!document.all)) {
if (e.which==2||e.which==3) {(message);return false;}}}

if (document.layers)
    {document.captureEvents(Event.MOUSEDOWN);document.onmousedown=clickNS;}
else    {document.onmouseup=clickNS;document.oncontextmenu=clickIE;}// -->
</script>

Author

Commented:
"a.marsh" -
I don't have a button which I can click to make test field disable. Second I have already used 'onFocus=this.blur()' but this doesn't disable the cut/copy/delete using mouse.


"rootnash"-
I had already tried this code earlier but this still allows selecting the value in text field and right click it and we can do cut/copy/delete in Netsacpe.This works fine only in IE.

Here is the  code which I tried ----

<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
<TITLE></TITLE>
</HEAD>
<BODY>

<form>
<input type='text' value=1000 >
</form>

<P>&nbsp;</P>

</BODY>
</HTML>

<script language=JavaScript>
<!--
var message="";
function clickIE() {if (document.all) {(message);return false;}}
function clickNS(e) {if
(document.layers||(document.getElementById&&!document.all)) {
if (e.which==2||e.which==3) {(message);return false;}}}

if (document.layers)
   {document.captureEvents(Event.MOUSEDOWN);document.onmousedown=clickNS;}
else    {document.onmouseup=clickNS;document.oncontextmenu=clickIE;}// -->
</script>






Commented:
Just use this then:

<html>
<head>
</head>
<body>
<form>
<input type="text" name="myText" value="" readonly onfocus="if(this.readonly){ this.blur(); }"<br>
</form>
</body>
</html>

There is no way you can 100% guarantee that the user will not be able to copy and paste the text....the easy option is for the user to disable javascript on their browser!! Then none of this code will work.

:o\

Ant

Commented:
or view source :p

Commented:
have you tried storing the data in a var.. and when submitting the form making sure the field is reset to the saved data.

Of course anyone who disables JS will be able to bypass everything.

Author

Commented:
cheekyci,

I can't submit the form. It's a page which the user wants to print.

Commented:
I haven't been able to find a solution to stop the cut and paste way of modifying fields...

How about a table with a transparent image that looks like a text field (disabled) and fill the table with the text you want.  Or just use an image.  Its the only way I can think of to gauruntee the text will not be modified.

Besides the onblur.. what about invoking the onChange to reset the field to its original text.

CJ

Commented:
well if its only a page to be printed, why would you use forms where you can simply use static text. that way it will no longer be a problem.

Author

Commented:
rootnash,
Its client requirement and I can't help it.....
Any way I think its not possible to do it netscape so I might have to push it as a browser issue and tell the client.
Asta CuTechnical consultant & graphic design
BRONZE EXPERT
Top Expert 2004

Commented:
Please update the expert here who have so willingly stepped in to help you, since much time has passed since your last comments, and Email notifications may not have been generated to the participating experts here due to some problems at that time.  If you've been helped, accept the respective question by that expert to grade and close it.

Somewhat off-topic, but important.

****************************** ALERT********************************
WindowsUpdate - Critical Update alert March 28, 2002 from Microsoft
http://www.microsoft.com/technet/treeview/default.asp?url=/technet/security/bulletin/ms02-015.asp
Synopsis:
Microsoft Security Bulletin MS02-015  
28 March 2002 Cumulative Patch for Internet Explorer
Originally posted: March 28, 2002
Summary
Who should read this bulletin: Customers using Microsoft® Internet Explorer
Impact of vulnerability: Two vulnerabilities, the most serious of which would allow script to run in the Local Computer Zone.
Maximum Severity Rating: Critical
Recommendation: Consumers using the affected version of IE should install the patch immediately.
Affected Software:
Microsoft Internet Explorer 5.01
Microsoft Internet Explorer 5.5
Microsoft Internet Explorer 6.0

Thought you'd appreciate knowing this.
":0)
Asta
ahosangFinance Systems Developer

Commented:
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:
PAQ  (Refund)
Please leave any comments here within the next seven days.
 
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
 
ahosang
EE Cleanup Volunteer
per recommendation

SpideyMod
Community Support Moderator @Experts Exchange

Explore More ContentExplore courses, solutions, and other research materials related to this topic.