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
<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:
- $(document).ready(function() {
- $('#date2_0').click(function(){
- $('#date3').addClass('{validate:{required:true}}');
- $('#date4').removeClass('{validate:{required:true}}');
- });
- $('#date2_1').click(function(){
- $('#date3').removeClass('{validate:{required:true}}');
- $('#date4').addClass('{validate:{required:true}}');
- });
- });
And if I were using a checkboxes I could use code similar to the code below
- // Show / Hide check box
- $(document).ready(function() {
- $("#med_field_002_other").click(function(){
- if ($("#med_field_002_other").is(":checked"))
- {
- $('#med_field_003').addClass('{validate:{required:true}}');
- $("#acommOther").show();
- }
- else
- {
- $('#med_field_003').removeClass('{validate:{required:true}}');
- $("#acommOther").hide();
- }
- });
- $("#acommOther").hide();
- var selector = "#med_field_002_asl, #med_field_002_cart, #med_field_002_seat, med_field_002_alt, med_field_002_diet";
- $(selector).click(function(){
- if (!$("#med_field_002_other").is(":checked")) {
- $('#med_field_003').removeClass('{validate:{required:true}}');
- }
- });
- });
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