JavaScript comma delimited input check boxes

Here is a quick example. http://jsfiddle.net/DXSDK/

<html>
<input type=”checkbox” onclick=”checkbox_clickHandler(1);”>
<input type=”checkbox” onclick=”checkbox_clickHandler(2);”>
<input type=”checkbox” onclick=”checkbox_clickHandler(3);”>
<input type=”checkbox” onclick=”checkbox_clickHandler(4);”>
<input type=”checkbox” onclick=”checkbox_clickHandler(5);”>
<input type=”checkbox” onclick=”checkbox_clickHandler(6);”>
<input type=”checkbox” onclick=”checkbox_clickHandler(7);”>
<input type=”checkbox” onclick=”checkbox_clickHandler(8);”>
<input type=”checkbox” onclick=”checkbox_clickHandler(9);”><br>

<input type=”text” id=”AccessList”>
</html>

<script>
function checkbox_clickHandler(SiteID) { var str = document.getElementById(“AccessList”).value; var res = str.split(“,”); var x = 0 ; for (var i = 0; i < res.length; i++) { if(!res[i]) { res.splice(i,1); } if (SiteID == res[i]) { res.splice(i,1); x = 1; break; } } if (x != 1) { res.push(SiteID); } document.getElementById(“AccessList”).value = res.toString(); }
</script>

Please follow and like us: