Reputation: 301
I'm very new to this and have limited knowledge (all self taught over the last few weeks). I have tried a number of solutions from similar questions that others have asked, and none seem to work for me.
I am trying to set the 'date_range' div to only be visible when the 'range' filter is selected. I'm using jQuery 1.8.2 and jQueryUI 1.9 (set with $.noConflict(); ).
My code is below (please be kind, I know I'm not very good at this), any help is appreciated.
<script>
$('#filters').is(function() {
if ($('#range').attr('checked')) {
$('#date_range').show();
} else {
$('#date_range').hide();
}
});
</script>
<div>
<form align="center" id="filters">
<input type="radio" id="last24" name="filter_radio" checked="checked"/><label for="last24">Last 24hrs</label>
<input type="radio" id="WTD" name="filter_radio" /><label for="WTD">WTD</label>
<input type="radio" id="last_week" name="filter_radio" /><label for="last_week">Last Week</label>
<input type="radio" id="range" name="filter_radio" /><label for="range">Range</label>
<div id="date_range">
<br />
<label for="from">From: </label><input type="text" id="from" name="from"/>
<label for="to">To: </label><input type="text" id="to" name="to" />
</div>
</form>
</div>
Upvotes: 2
Views: 18145
Reputation: 122
Try this code:-
This is jquery to hide and show:-
<script type="text/javascript" src="http://code.jquery.com/jquery.min.js" ></script>
<script>
function asfd(str)
{
if(str==true)
{
jQuery('div#renew').show();
}
else
{
jQuery('div#renew').hide();
}
}
</script>
This is where Jquery function called :-
<input type="checkbox" autocomplete="off" onchange="asfd(this.checked);"/>
This is the div which will hide or to show:-
<div id="renew" style="display: none ;">
........Content.........
</div>
Upvotes: 3
Reputation: 103365
You could try this
Markup:
<label><input id="last24" type="radio" name="filter_radio" value="1" />Last 24hrs</label>
<label><input id="WTD" type="radio" name="filter_radio" value="2" />WTD</label>
<label><input id="last_week" type="radio" name="filter_radio" value="3" />Last Week</label>
<label><input id="range" type="radio" name="filter_radio" value="4" />Range</label>
<div id="filter_radio-4" class="toHide" style="display:none">
<br />
<label for="from">From: </label><input type="text" id="from" name="from"/>
<label for="to">To: </label><input type="text" id="to" name="to" />
</div>
Javascript:
$(function() {
$("[name=filter_radio]").click(function(){
$('.toHide').hide();
$("#filter_radio-"+$(this).val()).show('slow');
});
});
DEMO: http://jsfiddle.net/chridam/FSrBC/
Upvotes: 0
Reputation: 1361
You can achieve it with this
$('#date_range').hide();
$('[name=filter_radio]').on('click', function(){
if($('#range').is(':checked')){
$('#date_range').show();
} else {
$('#date_range').hide();
}
});
Hope its simple and clear ..
Upvotes: 0
Reputation: 9869
Try this code
$(function(){
$('#date_range').hide();
$('#filters').on('click' ,'input[type=radio]', function(){
if (this.id == "range" && this.checked) {
$('#date_range').show();
} else {
$('#date_range').hide();
}
});
});
Check this DEMO
Hope it will help
Upvotes: 6