addClass to element based on drop down menu select

addClass to element based on drop down menu select

Hello,

I think I'm missing basic terminology again.  I have addClass/removeClass code working for child elements when a radio button or check box is clicked.  What I haven't figured out yet, is to addClass to a child element when a particular drop down menu value is selected.

so in the code below, if "1" is selected then I want to addClass required to phone1, otherwise no class is added to phone1

  1. <select name="date3" id="date3" tabindex="13">
     <option value="1">1</option> <option value="2">2</option>
    <option value="3">3</option>
    <option value="4">4</option>
    </select>
     <p><label for="phone1">Phone:</label> <input type="text" name="phone1" id="phone1" tabindex="14" /></p> 

If it were a checkbox, I could use the code below:


  1. $(document).ready(function() {
  2. $('#date2_0').click(function(){
  3. $('#date3').addClass('{validate:{required:true}}');
  4. $('#date4').removeClass('{validate:{required:true}}');
  5. });
  6. $('#date2_1').click(function(){
  7. $('#date3').removeClass('{validate:{required:true}}');
  8. $('#date4').addClass('{validate:{required:true}}');
  9. });
  10. });

And if I were using a checkboxes I could use code similar to the code below


  1. // Show / Hide check box
  2. $(document).ready(function() {
  3. $("#med_field_002_other").click(function(){
  4. if ($("#med_field_002_other").is(":checked"))
  5. {
  6. $('#med_field_003').addClass('{validate:{required:true}}');
  7. $("#acommOther").show();
  8. }
  9. else
  10. {
  11. $('#med_field_003').removeClass('{validate:{required:true}}');
  12. $("#acommOther").hide();
  13. }
  14. });
  15. $("#acommOther").hide();
  16. var selector = "#med_field_002_asl, #med_field_002_cart, #med_field_002_seat, med_field_002_alt, med_field_002_diet";
  17. $(selector).click(function(){            
  18. if (!$("#med_field_002_other").is(":checked")) {
  19. $('#med_field_003').removeClass('{validate:{required:true}}');
  20. }
  21. });
  22. });

But I'm stumped on what code to use for a specific value in a drop down menu (to addClass to a child element).

Thank in advance if anyone can point me in the right direction.

Peter T