1
I have a code that saves in a textarea values from a checkbox, but I cannot make the value be deleted from the textarea when the checkbox is unchecked.
var checkbox = document.getElementsByName('CP[]');
var teste = [];
function addCheck() {
for (var i = 0; i < checkbox.length; i++) {
if (checkbox[i].checked == true)
teste[i] = checkbox[i].value;
}
document.getElementById("cps").innerHTML = teste;
var textarea = document.getElementById("cps").value;
}
<input name='CP[]' id='CP01' type='checkbox' onclick='addCheck()' value="A">
<input name='CP[]' id='CP01' type='checkbox' onclick='addCheck()' value="B">
<input name='CP[]' id='CP01' type='checkbox' onclick='addCheck()' value="C">
<input name='CP[]' id='CP01' type='checkbox' onclick='addCheck()' value="D">
<input name='CP[]' id='CP01' type='checkbox' onclick='addCheck()' value="E">
<br />
<textarea name='cps' id='cps' cols='8' rows='1' value=''></textarea>
That’s right, thank you very much!
– Rocha
@Great rock. See you soon.
– Sergio