• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1797
  • Last Modified:

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>
0
jollykh
Asked:
jollykh
  • 3
1 Solution
 
GrandSchtroumpfCommented:
add a hidden field:
<input type="hidden" name="Numbers" value="4">
0
 
GrandSchtroumpfCommented:
> add a hidden field
and use "disabled" on you select.
0
 
jollykhAuthor Commented:
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.
0
 
GawaiCommented:
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 ?
0
 
GrandSchtroumpfCommented:
> 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.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now