jquery - Clear array and text box with javascript -
each time checkbox checked, below function called. problem need function should clear data available here.
let me explain problem first:
the concept of program update text box checkbox value - if 2 check boxes checked, text box have 2 values in , on.
i need function clear data on check box when click 3rd check box needs show 3rd checkbox's value removing first , second text area. should happen without reloading page
<script> function chkcontrol(j){ var textbox = document.getelementbyid("list"); var textbox1 = document.getelementbyid("val_id"); var values = []; var val_id=[]; if(document.getelementbyid(1).checked) { values.push('a1'); val_id.push('1'); } if(document.getelementbyid(2).checked) { values.push('a2'); val_id.push('2'); } if(document.getelementbyid(3).checked) { values.push("a3"); val_id.push('3'); } if(document.getelementbyid(4).checked) { values.push("a4"); val_id.push('4'); } if(document.getelementbyid(5).checked) { values.push("a5"); val_id.push('5'); } if(document.getelementbyid(6).checked) { values.push("a6"); val_id.push('6'); } textbox.value = values.join(","); textbox1.value = val_id.join(","); } function removeall(){ } </script> <input id="list" type="text" name="list"> <input id="val_id" type="text" name="val_id"> <input type="checkbox" name="ckb" value="a1" id="1" onclick='chkcontrol(0)';> <label for="1"></label> <input type="checkbox" name="ckb" value="a2" id="2" onclick='chkcontrol(0)';> <label for="2"></label> <input type="checkbox" name="ckb" value="a3" id="3" onclick='chkcontrol(0)';> <label for="3"></label>
i don't know need here, if need "clear" javascript array set length 0 (zero).
var = [0,1,2,3,4,5,6,7,8,9]; a.length = 0; // truncate array
mdn says: "you can set length property truncate array @ time."
hope helps you...
Comments
Post a Comment