Hide div select option on dropdown selection in HTML using jQuery
To get straight to the point here, I want to follow through. I want to hide a specific DIV when a specific one has been selected <OPTION>
in <SELECT>
.
Here's my HTML markup:
CHOICE
<select name="cutoffselect" id="cutoff" class="text ui-widget-content ui-corner-all" style="padding-right: 80px;">
<option value="">Choose One</option>
<option value="daily">Daily</option>
<option value="weekly">Weekly</option>
<option value="semimonthly">Semi Monthly</option>
<option value="monthly">Monthly</option>
</select>
and the DIV I want to hide if DAILY was selected.
PERIOD
<div class="input-group-addon" style="width:20%;" title='Filter By' id = "perioddiv">
<!--PERIOD-->
<label for="period" style="padding-right: 10px;margin-top:7px;" visible="false">Period</label>
<select name="period" id="period" class="text ui-widget-content ui-corner-all">
<option value="">Choose Period</option>
<option value="">1</option>
<option value="">2</option>
<option value="">3</option>
<option value="">4</option>
<option value="">5</option>
</select>
<!--PERIOD-->
</div>
I've tried using a different query, but I can't seem to do what I want. Here's the query I used but it doesn't work and if I can ask for another jQuery suggestion that might actually work more. Thanks everyone in advance.
HERE QUERY
<script type="text/javascript">
$("#cutoffselect").change(function(){
$("#perioddiv div:eq(" + $(this).attr("selectedIndex") + ")").show();
});
</script>
+3
source to share
7 replies
To hide the div with id=perioddiv
if option is selected daily
, you can try under jQuery:
<script type="text/javascript">
// bind change event using '#cutoff' as select id="cutoff"
$("#cutoff").change(function(){
// hide if selected value is "daily"
if($(this).val() == "daily")
$("#perioddiv").hide();
else
$("#perioddiv").show();
});
</script>
0
source to share