INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

How do I Hide/Show options elements by class

How do I Hide/Show options elements by class

(OP)
I have a large select element and would like to filter its options with some radio buttons. I tried jquery .hide()/.show() but no luck. Any suggestions appreciated.

CODE

<script type="text/javascript" language="JavaScript">
$( document ).ready(function() {
$('.Any').css('background-color','#ADD8E6') $('.TB').css('background-color','#FFE4B5') $('.QH').css('background-color','#90EE90') $('.PT').css('background-color','#FFC0CB') $('.AP').css('background-color','#FAFAD2')
}); function filterOptions(elem){ if (elem == 'All') { $('option').show(); } else { $('option').hide(); $('.' + elem).show(); } } </script>

CODE

<form action="targetReport.cfm" target="_blank" method="post">
 <select name="targetReport" id="targetReport">
  <option class="Mixed" value='AllBreedsHorseofTheYear.cfm'>Any Breed - Horse of the Year</option>
  <option class="Mixed" value='FairMeetChampion.cfm'>Any Breed - Fair Meet Champion</option>
  <option class="TB" value='TBHorseofTheYear.cfm'>TB - Horse of the Year</option>
  <option class="TB" value='TB2yFilly.cfm'>TB - Two Year Old Filly</option>
  <option class="TB" value='TB2yColt.cfm'>TB - Two Year Old Colt/Gelding</option>
  <option class="TB" value='TB3yFilly.cfm'>TB - Three Year Old Filly</option>
  <option class="TB" value='TB3yColt.cfm'>TB - Three Year Old Colt/Gelding</option>
  <option class="TB" value='TBChampionMare.cfm'>TB - Champion Mare</option>
  <option class="TB" value='TBChampionSire.cfm'>TB - Champion Stallion/Gelding</option>
  <option class="TB" value='TBLeadingRaceStockOwner.cfm'>TB - Leading Owner</option>
  <option class="TB" value='TBLeadingDam.cfm'>TB - Leading Dam of Racing Stock</option>
  <option class="TB" value='TBLeadingBreeder.cfm'>TB - Leading Breeder of Racing Stock</option>
  <option class="TB" value='TBLeadingSire.cfm'>TB - Leading Sire of Racing Stock</option>
  <option class="TB" value='TBLeadingSireOwner.cfm'>TB - Leading Sire Owner of Racing Stock</option>
  <option class="TB" value='TBLeadingFemaleSprinter.cfm'>TB - Leading Female Sprinter</option>
  <option class="TB" value='TBLeadingMaleSprinter.cfm'>TB - Leading Male Sprinter</option>
  <option class="TB" value='TBLeadingFemaleTurf.cfm'>TB - Leading Female Turf Runner</option>
  <option class="TB" value='TBLeadingMaleTurf.cfm'>TB - Leading Male Turf Runner</option>
  <option class="TB" value='TBLeadingClaimer.cfm'>TB - Leading Claimer of the Year</option>
  <option class="QH" value='QHHorseofTheYear.cfm'>QH - Horse of the Year</option>
  <option class="QH" value='QH2yFilly.cfm'>QH - Two Year Old Filly</option>
  <option class="QH" value='QH2yColt.cfm'>QH - Two Year Old Colt/Gelding</option>
  <option class="QH" value='QH3yFilly.cfm'>QH - Three Year Old Filly</option>
  <option class="QH" value='QH3yColt.cfm'>QH - Three Year Old Colt</option>
  <option class="QH" value='QHAgedMare.cfm'>QH - Aged Mare</option>
  <option class="QH" value='QHAgedStallion.cfm'>QH - Aged Stallion/Gelding</option>
  <option class="QH" value='QHLeadingRaceStockOwner.cfm'>QH - Leading Owner</option>
  <option class="QH" value='QHLeadingDam.cfm'>QH - Leading Dam of Racing Stock</option>
  <option class="QH" value='QHLeadingSire.cfm'>QH - Leading Sire of Racing Stock</option>
  <option class="QH" value='QHLeadingBreeder.cfm'>QH - Leading Breeder of Racing Stock</option>
  <option class="QH" value='QHLeadingSireOwner.cfm'>QH - Leading Sire Owner of Racing Stock</option>
  <option class="PT" value='PTHorseofTheYear.cfm'>Paint - Horse of the Year</option>
  <option class="PT" value='PT2yHorseofTheYear.cfm'>Paint - Two Year Old Horse of the Year</option>
  <option class="PT" value='PT3yHorseofTheYear.cfm'>Paint - Three Year Old Horse of the Year</option>
  <option class="PT" value='PTAgedHorseofTheYear.cfm'>Paint - Aged Horse of the Year</option>
  <option class="PT" value='PTLeadingDam.cfm'>Paint - Leading Dam of Racing Stock</option>
  <option class="PT" value='PTLeadingSire.cfm'>Paint - Leading Sire of Racing Stock</option>
  <option class="AP" value='APHorseofTheYear.cfm'>Appaloosa - Horse of the Year</option>
  <option class="AP" value='AP2yHorseofTheYear.cfm'>Appaloosa - Two Year Old Horse of the Year</option>
  <option class="AP" value='AP3yHorseofTheYear.cfm'>Appaloosa - Three Year Old Horse of the Year</option>
  <option class="AP" value='APAgedHorseofTheYear.cfm'>Appaloosa - Aged Horse of the Year</option>
  <option class="AP" value='APLeadingDam.cfm'>Appaloosa - Leading Dam of Racing Stock</option>
  <option class="AP" value='APLeadingSire.cfm'>Appaloosa - Leading Sire of Racing Stock</option>
 </select>
 <input type="submit" value="Print Preview">
</form>
<div>
 <input Name ="filter" type="radio" onclick="filterOptions('All')"> All
 <input Name ="filter" type="radio" onclick="filterOptions('Mixed')"> Mixed
 <input Name ="filter" type="radio" onclick="filterOptions('TB')"> TB
 <input Name= "filter" type="radio" onclick="filterOptions('QH')"> QH
 <input Name= "filter" type="radio" onclick="filterOptions('AP')"> AP
</div> 

Lyndon

RE: How do I Hide/Show options elements by class

Use <optgroup> elements or use javascript to remove or add options, hiding option elements with CSS does NOT actually 'hide' them from being selected as choices in the list.

Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.
Webmaster Forum

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close