Hi all, I have a problem that when I try to send any variables to a function using onclick, the checkbox doesn’t display.
Here is the example code:
[CODE]<!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.01//EN” “http://www.w3.org/TR/html4/strict.dtd”>
<html>
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=iso-8859-1″ />
<title>CheckBoxes</title>
</head>
<body>
<FORM Name=”myForm” Action=”” Method=”POST”>
</FORM>
</body>
<HEAD><META HTTP-EQUIV=”PRAGMA” CONTENT=”NO-CACHE”></HEAD><script language=”JavaScript” type=”text/javascript”>/**
* @author 3p
*/
var mytable = document.createElement(“Table”);
mytable.style.color = “#000000”;
mytable.border = “1”;
mytable.cellPadding =”5″;
mytable.style.borderWidth = “2”;
mytable.style.borderColor = “#000000”;
function addCheck(ID, captn, desc)
{
var newrow=mytable.insertRow(-1) //add new row to end of table
var chx = document.createElement(“Input”);
chx.setAttribute(“type”, “checkbox”);
chx.name= “perms”;
chx.value = ID;
chx.id = “C”+ID;
chx.style.backgroundColor = “#00FF00”;
chx.onclick = updatePermissions; //updatePermissions(ID); doesn’t work
//chx.addEventListener(‘click’, updatePermissions(ID), false);
//chx.attachEvent(“onclick”, updatePermissions(ID));
newcell=newrow.insertCell(0) //insert new cell to row
newcell.align = “center”;
newcell.appendChild(chx);
}
for (i=0; i< 2; i++) {
addCheck(i, i, i);
}
document.myForm.appendChild(mytable);
function updateT() {
updatePermissions(1);
}
function updatePermissions(chx) {
//Do Something with the data
}
function rePos() {
mytable.style.position = “absolute”;
mytable.style.top = myForm.offsetTop;
mytable.style.left = 30;
}
rePos();
</script>
</html>
Fairly straight forward, we make a table populate it with a couple of checkboxes.
Now I really want to have the line of code
[CODE]chx.onclick = updatePermissions;
looking more like:
[CODE]chx.onclick = updatePermissions(ID);
But If I do this, then none of the javascript displays on the page. (I have tried, IE7 and Maxthon2 UA’s).
I need a soloution to this as I need to have the form dynamically built. I have no Idea how many checkboxes there will be.
Cheers people.
Cheers!