Manish Shaw Manish Shaw - 5 months ago 14
jQuery Question

after clicking on checkbox a text box will appear

<script type="text/javascript" language="javascript">
function enabletxt(){
document.getElementById("chkAssociation").innerHTML="<input type='text' value=''>"
}
</script>
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)">
Comments