Is there any way to make a SELECT field in HTML as a read only field?

D

datactrl

Hi, all

Is there any way to make a SELECT field in HTML as a read only field?

Jack
 
I

Ivo

"datactrl" aka Jack asks
Is there any way to make a SELECT field in HTML as a read only field?

It is read-only by design, as far as i am aware. Perhaps you mean making it
impossible to alter the selected option(s). Then

<select onfocus="this.nextSibling.focus()">

works fine (if the next sibling is another form element).

<select onfocus="window.focus()">

makes the list flash open for a moment.
You realize that javascript will not available on many machines.
HTH
Ivo
 
D

datactrl

Hi, Ivo
Thanks a lot. Yes, I mean making it impossible to alter the selected option.
I try the way you advised. It works the most times but sometimes the drop
list stays there insteead of flashing a moment. Do you have the same
problem? I use IE6.

Jack
 
A

Alberto

Yeah I noticed.
Ok try:
<select onChange="this.selectedIndex=0">
You can change the zero (which means the very first option) with a number
representing the index of the option that you want to keep selected EVEN if
the user attempts to select another one.
ps note that selectedIndex is CASE SENSITIVE: the i must be uppercase

ciao
Alberto
http://www.unitedscripters.com/
 
D

datactrl

It works on when the original Selected Value is fixed. But my problem is the
selected value comes from a database on server. Just can't change back to
the original unless the original has been saved.

Jack
 

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,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top