readonly select element

K

kaeli

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>



--
 
R

Randy Webb

kaeli said:
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?
 
K

kaeli

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
 
K

kaeli

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;'>

--
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,073
Latest member
DarinCeden

Latest Threads

Top