Reputation: 769
I tried to show and hide a button in <fieldset>
by a javascript function.But it is not working.I did not find my mistake.
My FieldSet :
<fieldset class="buttons">
<dx:ASPxButton ID="btn11" runat="server" Text="Buton 1">
</dx:ASPxButton>
</fieldset>
My checkbox :
<input class="checkbox" id="ShowHideButton" name="ShowHideButton" type="checkbox" onchange="valueChanged()" />
<label for="ShowHideButton">ShowHideButton</label>
And my JavaScript function.
<script type="text/javascript">
function valueChanged() {
if ($('#ShowHideButton').is(":checked"))
$(".buttons").show();
else
$(".buttons").hide();
}
</script>
Upvotes: 0
Views: 5441
Reputation: 769
Thank you guys.I solved.I am a stupid I forgot add this library
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
Upvotes: 1
Reputation: 2931
try to use
http://jsfiddle.net/modaloda/7ZNzF/
$(document).ready(function() {
//set initial state.
$('#ShowHideButton').val($(this).is(':checked'));
$('#ShowHideButton').change(function() {
if($(this).is(":checked")) {
var returnVal = confirm("Are you sure?");
$(this).attr("checked", returnVal);
}else{
alert("sd");
}
$('#ShowHideButton').val($(this).is(':checked'));
});
});
Upvotes: 2
Reputation: 2292
On the client side the actual id of the button won't be ShowHideButton
ASP will generate a unique one for it.
You need to access it via clientid
in your javascript.
Try this:
function valueChanged()
{
if ($('#<%=ShowHideButton.ClientID%>').is(":checked"))
$(".buttons").show();
else
$(".buttons").hide();
}
Upvotes: 3