2

I am having one checkbox and one input text in a row .I want when a user checks the checkbox to diable the text and clear its value.

I tried this one but nothing: What is wrong?

HTML:

  <span style="width: 200px;font-size: 80%;"><input id="chkSendSummary" type="checkbox" name="ctl03$ctl00$ctl00$chkSendSummary" onclick="checkSendSummaryLetter();"></span>    
<input name="ctl03$ctl00$ctl00$txtSendSummary" type="text" id="txtSendSummary" class="NormalTextBox" style="width: 170px;">                 

  var chkSendSummaryLetter=document.getElementById('chkSendSummary');
    var txtSendSummaryLetter=document.getElementById('txtSendSummary');
            if (chkSendSummaryLetter.checked) {
                txtSendSummaryLetter.enabled = true;
            } else { 
                txtSendSummaryLetter.value = "";
                txtSendSummaryLetter.enabled = false;

            }

2 Answers2

2

You've created a custom property enabled, which has no effect on the DOM. Use disabled instead:

if (chkSendSummaryLetter.checked) {
    txtSendSummaryLetter.disabled = false;
} else { 
    txtSendSummaryLetter.value = "";
    txtSendSummaryLetter.disabled = true;
}
Teemu
  • 22,918
  • 7
  • 53
  • 106
0
<script type="text/javascript">

var chkSendSummaryLetter=document.getElementById('chkSendSummary');
var txtSendSummaryLetter=document.getElementById('txtSendSummary');
        if (chkSendSummaryLetter.checked) {
            txtSendSummaryLetter.value = "";
        hide();
        }
if
function hide() {
    document.getElementById('txtSendSummary').style.display = 'block';
}
</script>

This post already exists: (found in 2 seconds via google) javascript hide/show element

you could add a parameter within the function to make it have multiple purposes

Community
  • 1
  • 1
josh.thomson
  • 905
  • 9
  • 25
  • I cannot understand this one .Only i want to disable the input not hide or anything.Can you provide some working example? –  Oct 10 '14 at 12:07