PLEASE NOTE: These forums are no longer utilized and are provided as an archive for informational purposes only. All support issues will be handled via email using our support ticket system. For more detailed information on this change, please see this blog post.

Adding individual classes to options

  1. I realize it's Saturday, but I figured I'd ask anyway :)

    I have a dropdown form field where three of the items should only appear between two dates. I've already created a function to check the current date, and the function will add a "display:none;" all to the header so it'll hide the options I want. However, although I can add a class to the dropdown itself, I can't add specific classes to the individual options. The output simply gives

    <option value="whatever value">Option name</option>

    where I'd like the output to be

    <option value="whatever value" class="someclass">Option name</option>

    is there some sort of hook or something so I can make that happen?

    Posted 12 years ago on Saturday January 7, 2012 | Permalink
  2. You can achieve this with query, maybe something like this:

    [css]<script type="text/javascript">
    jQuery(document).ready(function(){
        jQuery("#inputID option[value='Field Value']").attr('class', 'some class');
    });
    </script>

    You can feel free to get more vague or specific with that selector, but that would work.

    Posted 12 years ago on Saturday January 7, 2012 | Permalink
  3. Sweet! Thanks, I'll give that a shot. I appreciate it!

    Posted 12 years ago on Saturday January 7, 2012 | Permalink
  4. Okay - that worked! it's adding my classes. However, it's still showing the items for some reason, even though the class is set to display:none. Very weird. I suspect something is overriding my setting.

    but thanks so much, I appreciate that!

    Posted 12 years ago on Saturday January 7, 2012 | Permalink
  5. Did you try display: none !important; Maybe that will help override? Can you post a link to your form?

    Posted 12 years ago on Saturday January 7, 2012 | Permalink
  6. HI Rob,

    sorry it took so long to get back to you :)

    I did try the "important!" thing, and it didn't work. (apparently, option tags can't be set with "display:none;" from what I found when googling - especially in IE. I couldn't get some of the options to bold, either. Apparently, they ignore styling on individual items.)

    So I did the workaround instead: created the form for the "regular" pricing, then duplicated the form and replaced the "regular" pricing with the "mid-year" discounted pricing. Then I used my custom function (that checks the current data against the required dates) and if it's a regular day of the year, it displays the "regular price" form on the page, and if it's between the 2 mid-year dates. it pulls in the "reduced pricing" form on the page. Works great :)

    I have to edit 2 forms instead of one (if anything major gets changed) but it's working fine anyway!

    Posted 12 years ago on Monday January 30, 2012 | Permalink
  7. Nice, glad you got it creatively working! :)

    Posted 12 years ago on Monday January 30, 2012 | Permalink