Manish Shaw Manish Shaw - 1 year ago 40
Javascript Question

I am new to html. I want that after clicking on checkbox "Others", a text box will appear

function enabletxt(){
document.getElementById("chkAssociation").innerHTML="<input type='text' value=''>"

<input type="checkbox" name="hobbies" value="Dancing">Dancing
<input type="checkbox" name="hobbies" value="Painting">Painting
<input type="checkbox" name="hobbies" value="Others" onChange="javascript:enabletxt();" ID="chkAssociation" runat="server" />Others

Answer Source

What you could do:

function enableText(checkBox) {
    if (checkBox.nextSibling.tagName != 'INPUT') {
        var input = document.createElement('input');
        input.type = "text";
        checkBox.parentNode.insertBefore(input, checkBox.nextSibling);


<input type="checkbox" name="hobbies" value="Dancing" onchange="enableText(this)">