Adding a link to a table built in Javascript
-
Hi all, This is hopefully a very simple question however I do not know the answer to it. I am trying to link a cell from a table created in Javascript to another function.
var cell_1 = document.createElement("td");
cell_1.style.textAlign = "center";
cell_1.appendChild(document.createTextNode("Hi"));
onclick = myFunction();This code ALL works apart from the onclick function, all I wanted to do is when the cell is clicked for example an alert message pops up. Hopefully that makes sense and if anybody can help that would be helpful :)
-
Hi all, This is hopefully a very simple question however I do not know the answer to it. I am trying to link a cell from a table created in Javascript to another function.
var cell_1 = document.createElement("td");
cell_1.style.textAlign = "center";
cell_1.appendChild(document.createTextNode("Hi"));
onclick = myFunction();This code ALL works apart from the onclick function, all I wanted to do is when the cell is clicked for example an alert message pops up. Hopefully that makes sense and if anybody can help that would be helpful :)
-
Hi all, This is hopefully a very simple question however I do not know the answer to it. I am trying to link a cell from a table created in Javascript to another function.
var cell_1 = document.createElement("td");
cell_1.style.textAlign = "center";
cell_1.appendChild(document.createTextNode("Hi"));
onclick = myFunction();This code ALL works apart from the onclick function, all I wanted to do is when the cell is clicked for example an alert message pops up. Hopefully that makes sense and if anybody can help that would be helpful :)
It might be better to create an a tag with a javascript: url:
var cell_1 = document.createElement("td");
cell_1.style.textAlign = "center";
var link = document.createElement("a");
link.appendChild(document.createTextNode("Hi"));
link.href = 'javascript:myFunction()';That way, you get the usual link semantics (underlining, colour cues, cursor, tab order entry).
-
Hi all, This is hopefully a very simple question however I do not know the answer to it. I am trying to link a cell from a table created in Javascript to another function.
var cell_1 = document.createElement("td");
cell_1.style.textAlign = "center";
cell_1.appendChild(document.createTextNode("Hi"));
onclick = myFunction();This code ALL works apart from the onclick function, all I wanted to do is when the cell is clicked for example an alert message pops up. Hopefully that makes sense and if anybody can help that would be helpful :)
alternet way cell_1.onclick = new Function ('myFunction()');
-
Hi all, This is hopefully a very simple question however I do not know the answer to it. I am trying to link a cell from a table created in Javascript to another function.
var cell_1 = document.createElement("td");
cell_1.style.textAlign = "center";
cell_1.appendChild(document.createTextNode("Hi"));
onclick = myFunction();This code ALL works apart from the onclick function, all I wanted to do is when the cell is clicked for example an alert message pops up. Hopefully that makes sense and if anybody can help that would be helpful :)
to attach events see this // +++++ attach even function AtEv(X00,X01,X02,X03) // X00 pointer of object with event // X01 kind of event, string e.g. 'mouseover' // X02 pointer of event handler // e.g. keyDownTextField (e) // { // var keyCode = e.keyCode; // //... // } // X03 false bubbling event allowed // true bubbling event not allowed: Capturing of event thru handler // must be identical with avent deatch // returns true if event attched { var X04=false; // insert here checking of pointer and string ... if(X00.attachEvent) { X04=X00.attachEvent('on'+X01,X02); } else { if(X00.addEventListener) { X00.addEventListener(X01,X02,X03); X04=true; } } return X04; } // +++++ detach event function DatEv(X00,X01,X02,X03) // params see AtEv { var X04=false; // insert here checking of pointer and string ... if(X00.detachEvent) { X04=X00.detachEvent('on'+X01,X02); } else { if(X00.removeEventListener) { X00.removeEventListener(X01,X02,X03); X04=true; } } return X04; } example function EventHandler(e,X00) // e.g. X00 param // e placeholder for event { // do something with X00 and or e } // ----- create dynamic event handler var pointerOfDynamicEventHandler=new Function('e','EventHandler(e,' + here the value of X00 + ')'); // check pointer ... // ----- attach dynamic event handler var booleanFlag=AtEv(pointerofObjectWithEvent,'click',pointerOfDynamicEventHandler,false); // ------ don't forget to deatch event if you this not need