Make Select option readonly

Posted on 2006-05-17
Last Modified: 2011-04-14
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>
Question by:jollykh
    LVL 30

    Accepted Solution

    add a hidden field:
    <input type="hidden" name="Numbers" value="4">
    LVL 30

    Expert Comment

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

    Author Comment

    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.
    LVL 20

    Expert Comment

    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 ?
    LVL 30

    Expert Comment

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

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

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Join & Write a Comment

    Suggested Solutions

    Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
    Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
    In this Micro Tutorial viewers will learn how to create navigation buttons that change on rollover, using CSS (Continuation of the CSS Image Sprite tutorial) Create a parent ID for all the list items       - Specify position: absolute and display: block…
    In this tutorial viewers will learn how to embed videos in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <video> tag to insert a video. Define the src as the URL of your video; this is similar to …

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now