Mary Plissey
Mary Plissey

Reputation: 13

How do you hide a dropdown box using java script/jquery

I have the following code to hide an essay question or open text.
I'd like to have the same effect but hide a drop down box.

In this example below if you select the "I will write in my choice below" the essay question will auto remove. I need to change this essay question to a drop down and I need the supporting Jquery to make the drop down dissaper if the write in choice is selected.

Please select your First Choice from the drop down or tell us that you will "Write In" or choice by selecting "I will "Write In" my choice below.
__________________________________
__________________________________
__________________________________

Q. I will "Write In" my choice below.

jQuery(function($){
   $('input[type=checkbox]',$('#table1')).click(function(){
     if($(this).is(':checked')){
        $('textarea',$('#table1')).empty().hide();
     } else {$('textarea',$('#table1')).show();}
   });
});

Thank you!

Upvotes: 1

Views: 626

Answers (1)

Roko C. Buljan
Roko C. Buljan

Reputation: 206699

jsBin demo

HTML

  <p>Please select your First Choice from the drop down or tell us that you will "Write In" or choice by selecting "I will "Write In" my choice below.</p>
   
  <select id="choose_question">
    <option selected="selected">Choose a question</option>
    <option value="q1">Question 1</option>
    <option value="q2">Question 2</option>
    <option value="q3">Question 3</option>
    <option value="q4">Question 4</option>    
  </select>
  
  <br>
  
  <input id="ill_write" type="checkbox" /> I will write in my question.
  
  <br>
  
  <input id="my_question" type="text" value="" style="display:none; width:300px;"/>

jQuery

$('#choose_question').change(function(){  
  $('#my_question').fadeTo(50,0);
  $('input#ill_write').prop('checked', false);
});

$('#ill_write').change(function(){  
  $('#my_question').fadeTo(500,1); 
});

Upvotes: 1

Related Questions