javascript - How to call to a function, with a string -



javascript - How to call to a function, with a string -

i creating string headlines of table, making checkbox each headline, , should hide col if unchecked , show if checked. function set checkbox in div.

i calling function when page loaded (onload in body)

this function:

function getfirstrow(table) { var table = document.getelementbyid(table); var row = table.getelementsbytagname('tr')[0]; var cells = row.getelementsbytagname('th'); var str = ""; (var i=0; < cells.length; i++) { str += "<input type='checkbox' onclick='hideorshowcol('treestable', "+i+", this);' checked='checked' />" + cells[i].innerhtml + " "; } document.getelementbyid("hideandshow").innerhtml = str; }

and hide/show function:

function hideorshowcol(table, col, e) { alert(e.checked); var iftoshow = ""; if (e.checked) iftoshow = "table-cell"; else iftoshow = "none"; var gettable = document.getelementbyid(table); var tds = gettable.getelementsbytagname("tr"); (var = 0; < tds.length; i++) { tds[i].childnodes[col].style.display = iftoshow; } }

so problem is not calling function when creating check boxes first function, when writing straight in html works fine, this:

<input type="checkbox" onclick="hideorshowcol('treestable', 2, this);" checked="checked" />

some 1 know can be?? tried everything... thanks.

"<input type='checkbox' onclick='hideorshowcol('treestable', "+i+", this);' checked='checked' />" invalid because of single quotes areound 'treestable' nested within single quote onclick.

try changing "<input type='checkbox' onclick='hideorshowcol(\"treestable\", "+i+", this);' checked='checked' />"

javascript .net html5

Comments

Popular posts from this blog

web services - java.lang.NoClassDefFoundError: Could not initialize class net.sf.cglib.proxy.Enhancer -

Accessing MATLAB's unicode strings from C -

javascript - mongodb won't find my schema method in nested container -