stalwil
07-22-2010, 11:56 PM
Hey Guys,
I'm trying to add an input field once a checkbox is checked and then delete that same input field when the same checkbox is unchecked. I have the code that does this but when i uncheck it the second time my input field doesnt get removed it just stays there and when i check the checkbox another input field gets added. Can someone help me? Please see my code below.
function add_input(){
if ($('input[name=foo]').is(':checked')) {
document.getElementById('addInput').innerHTML += "<input id='yes' name='chk1' value=''/>";
}
else{
removeItem(this);
}
}
function removeItem(){
var d = document.getElementById('addInput');
d.removeChild(yes);
}
I'm trying to add an input field once a checkbox is checked and then delete that same input field when the same checkbox is unchecked. I have the code that does this but when i uncheck it the second time my input field doesnt get removed it just stays there and when i check the checkbox another input field gets added. Can someone help me? Please see my code below.
function add_input(){
if ($('input[name=foo]').is(':checked')) {
document.getElementById('addInput').innerHTML += "<input id='yes' name='chk1' value=''/>";
}
else{
removeItem(this);
}
}
function removeItem(){
var d = document.getElementById('addInput');
d.removeChild(yes);
}