Show a text field on a specific option select

為{幸葍}努か 提交于 2019-12-07 00:10:54

Look at this: http://jsfiddle.net/a8ZWx/

You may use the change event of the select element to decide whether to show or hide the text box.

jsfiddle Example

Css

.hiddenField{
  display: none;
}

Html:

<select id="myOptions"> 
    <option value="Option 1">Option 1</option>
    <option value="Option 2">Option 2</option>
    <option value="Option 3">Option 3</option>   
</select>
<input type="text" class="hiddenField" id="myTextBox" />

jQuery

$(document).ready(function(){
    $('#myOptions').change(function(){
       $(this).val() == "Option 2" ? $('#myTextBox').show() : $('#myTextBox').hide();
    });
});
$('#myselect').change(function(){

var val =$("#myselect :selected").val();

if(val == 'Option 3'){
      $('#textbox').show();

}
else{
     $('#textbox').hide();
}

});
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!