Manish Shaw Manish Shaw - 5 months ago 9
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=''>"
}


Hobbies:
<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

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

and

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