SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

i need to write a javascript code that make the checkbox if checked view a textbox and if not checked the text box is invisable automatically without having a button to click on it to do that

<asp:Content ID="PageHead" ContentPlaceHolderID="PlaceHolderAdditionalPageHead" runat="server">
    <script type="text/javascript">

            var checked_status = this.checked;
            if(checked_status == true) {
            else { $('#txt').hide();
        }); </script>

<asp:Content ID="Main" ContentPlaceHolderID="PlaceHolderMain" runat="server">
    <input type="checkbox" id="checkbox"/>
    <input type="text" id="txt" style="display:none"/>
share|improve this question
is the script you used working or not? – Furqan Jun 17 '12 at 8:22

First: id in html elements and javascript are case sensitive:

#Checkbox ≠ #checkbox 

Second, change event is better than click for a checkbox.

$("#checkbox").change(function() {
   var checked =":checked");
   if (checked) {

Third, you should wait until your dom is loaded, by declaring your script in $(document).ready:

$(document).ready(function() {
   $("#checkbox").change(function() {
      var checked = $(this).is(":checked");
      if (checked) {
share|improve this answer
thanks this was really helpful – sarah Jun 17 '12 at 14:50
what if i wanted to make the same thing in but in – sarah Jun 17 '12 at 16:37
if the value in the select should decide if #txt is visible or not, you can use change event, instead of checked you can use val() of the select. – Anatoly Mironov Jun 17 '12 at 20:39
yes that is what i did but it didnt work <script> $(document).ready(function () { $("#selection").change(function () { var mySelect = document.myform.myselectbox; </script> <form action="#" id="myform"> Selection: <select id='selection' > <option >sarah</option> <option >mai</option> <option >alaa</option> <option >salma</option> <option id="Other" >laila</option></select> <input type="text" id="txta" style="display:none" /> var selIndex = mySelect.selectedIndex; if ($(this).val() == 'Other') { $('#txta').show(); } else { $('#txta').hide(); } }); }); – sarah Jun 18 '12 at 7:05
is there any unchecked keyword (":unchecked") exists like (":checked"). in my case unchecked event doesn't fire. ? anyone pls help, how to trigger a unchecked event, when a checkbox is checked first and then unchecked again. – SaMolPP Oct 27 '15 at 5:40

Try this simpler to validate whether the checkbox is checked or not:

share|improve this answer
How to capture the unchecked event ? in my case, if i uncheck the already checked checkbox, I want to make a tetxbox's value empty.Is this possible? Is there anything like this exist: var unchecked = $(this).is(":unchecked"); – SaMolPP Oct 27 '15 at 9:26

Your Answer


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.