473,322 Members | 1,234 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

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 12836
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Jonathan | last post by:
Does anyone know if it's possible to force a 'select' element (or select1) to bind each selected value to a seperate element when written to a file, instead of just putting all the values in one...
1
by: Covad | last post by:
Hi all, For some reason my change() function is only called when the page loads. I'd much rather it gets called when the select changes. Here's the code: window.onload = init; function...
1
by: Marek Mänd | last post by:
<select multiple style="height:200px;"> <option>a <option>b </select> Why does Mozilla draw the vertical scrollbar to the SELECT html element? There is plenty of void room below two OPTIONs in...
4
by: Rithish | last post by:
Is there a way to obtain the height of a <SELECT> element dynamically, i.e. through javascript? I want to dynamically display a list box onFocus of a text box element. Also, if the list box...
13
by: Oliver Hauger | last post by:
Hello, In my html form I show a select-element and if this element is clicked I fill it per JavaScript/DOM with option-elements. I use the following code: <!DOCTYPE HTML PUBLIC "-//W3C//DTD...
2
by: Rob Long | last post by:
Hi I have an HTML select element in my page and it's multiple property is disabled (one item at a time mode) but I still want to transfer all the items in the select to the server when the form...
3
by: alvinwoon | last post by:
Hi guys, I find it frustrating that I need to sniff out IE to make event handler for the form's select element work across different browsers. Here's a summary of what I have right now: var...
5
by: Andy Chambers | last post by:
Hi, On both Opera and Firefox, getElementsByTagName doesn't find anything apart from <optionelements inside a select element. Why is this? Here's a page that demonstrates this behaviour. I'd...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.