View Full Version : READONLY attribute of input textbox doesn't work in Netscape 4x
jeepzy3
07-02-2002, 06:43 PM
I have the following input text box:
<input TYPE="TEXT" NAME="org_code" VALUE="" READONLY MAXLENGTH=25 SIZE=25>
This works in IE, but not in Netscape 4.75. In netscape, I can modify what is in the input text box. Is there a workaround for this?
joh6nn
07-02-2002, 06:59 PM
i think readonly is one of those microsoft only things. try using "disabled" instead
adios
07-02-2002, 08:29 PM
<html>
<head>
<title>untitled</title>
<script type="text/javascript" language="JavaScript">
function toggle_readonly(control) {
if (typeof control.readOnly != 'undefined')
control.readOnly = (control.readOnly) ? false : true;
else if (control.onfocus != null) control.onfocus = null;
else control.onfocus = function() { this.blur() };
}
</script>
</head>
<body>
<form>
<input type="text" name="org_code" size="25" maxlength="25" readonly="readonly"
onfocus="if(typeof this.readOnly=='undefined')this.blur()"><br>
<input type="button" value="Toggle Readonly" onclick="toggle_readonly(org_code)">
</form>
</body>
</html>
whammy
07-03-2002, 12:25 AM
This also works...
<form>
<input type="text" value="blah" onchange="this.value=this.defaultValue" />
</form>
adios
07-03-2002, 12:32 AM
yo whammy...
Your alternative has a problem - the field reverts after it loses focus, possibly leaving the user thinking the change has been made.
whammy
07-03-2002, 12:41 AM
True... but it does work (at least in NS 4.7 which I have installed)! It also works well in combination with other methods like "readonly" or "disabled"...
Of course you could also use onkeyup, onkeydown, onkeypress, onblur, etc. depending on the browser and what you want to do... or even an alert box, like:
<form>
<input type="text" value="blah" onchange="alert('Yo! Don\'t be changin\' this!'); this.value=this.defaultValue" />
</form>
I know you're well aware of this, adios, since you're still a couple of light-years ahead of me in javascript programming (and you have taught me a lot)... I'm just putting in my two cents worth.
But the main thing I'm assuming is that if you don't want the value of the text field changed (since he originally had it disabled), then you don't really care what the user has typed in anyway... right?
:D
adios
07-03-2002, 01:36 AM
I always turn to Jukka "Yucca" Korpela in cases like this:
http://www.cs.tut.fi/~jkorpela/forms/readonly.html
Thanks for the comps....;)
jeepzy3
07-03-2002, 04:16 AM
Thanks adios and whammy. It's always good to know a couple ways to do the same thing.
I'm learning a lot already.
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.