Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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 JavaScrip func.

                  <script type="text/javascript">

                    function valueChanged()
                    {

                        if ($('#ShowHideButton').is(":checked"))
                            $(".buttons").show();
                        else
                            $(".buttons").hide();

                    }

                </script>
share|improve this question
 
Have you inspect the page and see what is the state of fieldset and what is the state of dx:ASPxButton ? –  kostas ch. Nov 20 at 12:04
 
See for any errors in console. ctrl+shift+j in google chrome. –  Subin Jacob Nov 20 at 12:19
 
@Mehmet Akyel can you give jsfiddle. –  Prateek Nov 20 at 12:31
add comment

3 Answers

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

}
share|improve this answer
add comment

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'));        
});
});
share|improve this answer
add comment

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>
share|improve this answer
 
:) don't said that –  Mahmoude Elghandour Nov 20 at 12:49
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.