How to disable a text box and clear value with pure javascript when a checkbox is checked -
I have an input text in a checkbox and row. I want to clear the value of when a user checks the checkbox to dial text
I tried this one but nothing: What's wrong?
HTML:
& lt; Span style = "width: 200px; font-size: 80%;" & gt; Input id = "chkSendSummary" type = "checkbox" name = "ctl03 $ ctl00 $ ctl00 $ chkSendSummary" onclick = "checkSendSummaryLetter ();" & gt; & Lt; / Span & gt; & Lt; Input name = "ctl03 $ ctl00 $ ctl00 $ txtSendSummary" type = "text" id = "txtSendSummary" class = "normal textbox" style = "width: 170px;" & Gt; Var chkSendSummaryLetter = document.getElementById ('chkSendSummary'); Var txtSendSummaryLetter = document.getElementById ('txtSendSummary'); If (chkSendSummaryLetter.checked) {txtSendSummaryLetter.enabled = true; } And {txtSendSummaryLetter.value = ""; TxtSendSummaryLetter.enabled = false; }
You have created a custom property enabled on which DOM has had no effect instead Use disabled instead: if (chkSendSummaryLetter.checked) {txtSendSummaryLetter.disabled = false; } And {txtSendSummaryLetter.value = ""; TxtSendSummaryLetter.disabled = true; }
Comments
Post a Comment