469,323 Members | 1,560 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,323 developers. It's quick & easy.

readonly select element

All,

I have need of a readonly select element that looks and acts disabled to
the user. The problem with the disabled attribute is that the value
isn't passed to the handler, so I'm using readonly. Problem with
readonly is that is allows focus, which when the user highlights, then
hits backspace (as if to change the field), the browser does a
history.back. This is confusing to users.

The following code works great in NN6, but IE ignores it.
Any suggestions?

Desired behaviour: clicking on the element does nothing; nothing can be
selected. Element cannot have focus.
Behavior acheived in NN6.
Behavior in IE: clicking selects it. Changing the selection changes it.
(tried onChange return false, etc).

<html>
<head>
<title> New Document </title>
</head>

<body>

<form name="f1">
<select name='choice' id='choice' readonly style='background-color:
#ababab' onFocus='this.blur(); return false;'>
<option value='' selected> </option>
<option value='Y'>Y</option>
<option value='N'>N</option>
</select>
</form>

</body>
</html>

--
--
~kaeli~
Local Area Network in Australia:... the LAN down under.
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace

Jul 20 '05 #1
4 12660
kaeli wrote:
All,

I have need of a readonly select element that looks and acts disabled to
the user. The problem with the disabled attribute is that the value
isn't passed to the handler, so I'm using readonly. Problem with
readonly is that is allows focus, which when the user highlights, then
hits backspace (as if to change the field), the browser does a
history.back. This is confusing to users.

The following code works great in NN6, but IE ignores it.
Any suggestions?

Desired behaviour: clicking on the element does nothing; nothing can be
selected. Element cannot have focus.
Behavior acheived in NN6.
Behavior in IE: clicking selects it. Changing the selection changes it.
(tried onChange return false, etc).

<html>
<head>
<title> New Document </title>
</head>

<body>

<form name="f1">
<select name='choice' id='choice' readonly style='background-color:
#ababab' onFocus='this.blur(); return false;'>
<option value='' selected> </option>
<option value='Y'>Y</option>
<option value='N'>N</option>
</select>
</form>

</body>
</html>


Why not just use a hidden field to store the original value?

window.onload=setHidden;
function setHidden(){
document.f1.choice.value = document.f1.displayedChoice.value;
}
<form name="f1">
<select name='fakeChoice' readonly style='background-color:#ababab'>
<option value='' selected> </option>
<option value='Y'>Y</option>
<option value='N'>N</option>
</select>
<input type="text" name="choice" value="">
</form>

Not sure I want to ask why you are using a select list if you don't want
it used. Or are you toggling the readonly?

--
Randy

Jul 20 '05 #2
In article <h4********************@comcast.com>, hi************@aol.com
enlightened us with...

Why not just use a hidden field to store the original value?


The users want a consistent appearance.
This was how it was done originally.

Thanks, though.

Anyone else?

--
--
~kaeli~
Kill one man and you are a murderer. Kill millions and you
are a conqueror. Kill everyone and you are God.
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace

Jul 20 '05 #3
In article <h4********************@comcast.com>, hi************@aol.com
enlightened us with...

Not sure I want to ask why you are using a select list if you don't want
it used. Or are you toggling the readonly?


Because the users want a consistent appearance. Elements on the page
they can edit are normal looking. Elements they can't are greyed out.
Users have different permissions, so the screen has elements they can
edit and elements they can't.
The elements are written dynamically with JSP taglibs that look at a
session var to tell what permissions a user has.

Originally, elements they could edit were elements and stuff they
couldn't edit was plain text with hidden inputs.

--
--
~kaeli~
Kill one man and you are a murderer. Kill millions and you
are a conqueror. Kill everyone and you are God.
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace

Jul 20 '05 #4
In article <MP************************@nntp.lucent.com>,
ti******@NOSPAM.comcast.net enlightened us with...

Desired behaviour: clicking on the element does nothing; nothing can be
selected. Element cannot have focus.
Behavior acheived in NN6.
Behavior in IE: clicking selects it. Changing the selection changes it.
(tried onChange return false, etc).


The following worked in IE6 and NN6. Not tested in other browsers.
<select name='choice' id='choice' readonly style='background-color:
#ababab'
onFocus='this.initialSelect = this.selectedIndex;'
onChange='this.selectedIndex = this.initialSelect;'>

--
--
~kaeli~
Why do they sterilize the needles for lethal injections?
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace

Jul 20 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Jonathan | last post: by
4 posts views Thread by Rithish | last post: by
2 posts views Thread by Rob Long | last post: by
5 posts views Thread by Andy Chambers | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by mdpf | last post: by
reply views Thread by harlem98 | last post: by
reply views Thread by listenups61195 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.