dynamic onclick

by Kyrylo Slatin

HTML

<div id="divCheckbox"></div>
<table id="tbl">
    <tbody>
        
    </tbody>
</table>
<input type="button" value="add checkbox" onclick="addCheckboxItems({combobox:{value:'check'}});"/>

JavaScript

addCheckboxItems  = function(form){
    var newBox = ('<input type="checkbox" name="checkBoxItem" onclick="JavaScript:addRowItems(this)"; id="checkBoxItemId" value="' + form.combobox.value +'"'+ '>'+form.combobox.value);
    document.getElementById("divCheckbox").innerHTML = newBox;

    };
addRowItems = function(element){
    alert('Hi');
    if(document.getElementById("checkBoxItemId").checked){
        var tableRef =  document.getElementById('tbl').getElementsByTagName('tbody')[0];
        var newRow   = tableRef.insertRow(tableRef.rows.length);
        var td1 = document.createElement("td")
        var strHtml1 = document.getElementById('checkBoxItemId').value;
        td1.innerHTML = strHtml1.replace(/!count!/g,count);

        var td2 = document.createElement("td")
        var strHtml2 = "NA";
        td2.innerHTML = strHtml2.replace(/!count!/g,count);

        var td3 = document.createElement("td")
        var strHtml3 = "<a>Remove</a>";
        td3.innerHTML = strHtml3.replace(/!count!/g,count);

        newRow.appendChild(td1);
        newRow.appendChild(td2);
        newRow.appendChild(td3);

        tableRef.appendChild(newRow);
    }
}