Link to home
Start Free TrialLog in
Avatar of jollykh
jollykh

asked on

Make Select option readonly

Hello Experts,

I need to make a select option readonly.  I can't use "disabled" because I still need to capture the field values, and I don't want to use JavaScript.  

Any ideas on how this can be accomplished?

<select name="Numbers">
  <option value="1">One</option>
  <option value="2">Two</option>
  <option value="3">Three</option>
  <option selected="selected" value="4">Four</option>
</select>
ASKER CERTIFIED SOLUTION
Avatar of GrandSchtroumpf
GrandSchtroumpf

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of GrandSchtroumpf
GrandSchtroumpf

> add a hidden field
and use "disabled" on you select.
Avatar of jollykh

ASKER

Hi GrandSchtroumpf,

The problem is that the select option changes so that I will not know the selected option ahead of time.  In addition, the names can't be the same for both the select statement and the hidden type.
if u set  <select name="Numbers" disabled> then u wil not able to choose from

<select name="Numbers" readonly>  will be ok if u try

wat acually u wish to achive ?
> because I still need to capture the field values
What do you mean by that?  You mean that the "Numbers=4" needs to be submitted to the form handler?  In that case, using a hidden field will work.

> I will not know the selected option ahead of time.
if you want it to be readonly, then the selected value won't change.  this means that you know the selected option ahead of time.

another solution is to only leave the selected option:

<select name="Numbers">
  <option selected="selected" value="4">Four</option>
</select>

This will be read-only in the sense that the value will always be 4.