0

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>
3
  • Have you inspect the page and see what is the state of fieldset and what is the state of dx:ASPxButton ? Commented Nov 20, 2013 at 12:04
  • See for any errors in console. ctrl+shift+j in google chrome. Commented Nov 20, 2013 at 12:19
  • @Mehmet Akyel can you give jsfiddle. Commented Nov 20, 2013 at 12:31

3 Answers 3

3

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();

}
Sign up to request clarification or add additional context in comments.

Comments

2

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'));        
});
});

Comments

1

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>

1 Comment

Why are you putting this here? It's a comment and should be in the comments area. Please familiarise yourself with SO.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.