Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

onclick event not firing

Status
Not open for further replies.

jrlaughlin

Programmer
Jul 31, 2003
2
US
Hello all.

Here is my situation. I'm inserting a row into a table from a child window using javascript. The following code assumes that the variable "table" has been defined.



Code:
row = table.insertRow(-1);
row.onclick = 'java script:alert("hi")';


Then I go on to add some cells to the row and content in the cells. Then I close the child window and I am looking at the table with the new row.

My problem is that when I click on the new row, the onclick event seems to not be firing.

Any help would be appreciated.

James.
 
First, javascript is one word.

Second, event handlers already target the scripting languages, so you don't need to add the "javascript:" preface to the function being called.

So, your onclick event handler IS firing, but you aren't telling it to do anything coherent.
 
Hi James,

I have exactly the same problem with the onclick event not firing.
Have you found a way around it yet?

Following is a snippet of code I'm using


Sam



function addToTable(i)
{
var x=document.getElementById("ParentTable").insertRow(i);
var newCell=x.insertCell(0);
lastParent++;
newCell.innerHTML="&nbsp;<input id='Parent" + lastParent + "' type='text' size='35' maxlength='25' value='' >";
newCell.style.backgroundColor="lightblue";
newCell.style.border="0";
newCell.style.cursor="pointer";
newCell.innerText=NewParentCode.value;
newCell.onclick='MyFunction()'; // this is never called
NewParentCode.value="";
NewParentCode.style.display="none";
document.getElementById("ParentTable").disabled=false;
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top