Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Jul 2011
    Thanked 0 Times in 0 Posts

    Question Dynamic onclick add to TD not working :(

    Hi folks,

    I'm frustrated . I've been trying to get this single piece of code to work. I've looked at quite a few sources out there, but everything I try fails.

    My site uses AJAX to upload a file, and once complete I dynamically add the file name, size, description, etc to a table.

    I have a javascript method that will allow me to download the file once uploaded - and I put an onclick event into some of the TDs in the row I added. (Note: I didn't want to put it in the TR because I also have a delete button in the row).

    I've tried

    1. cell1.onclick = 'javascript:downloadAttachmentFile('+attachID+');';
    2. cell1["onclick"] = new Function("downloadAttachmentFile('+attachID+')");
    3. cell3.setAttribute('onclick','javascript:downloadAttachmentFile('+attachID+');');
    but none seem to work!! I know the function is ok because the files that are already on the page work correctly, meaning it's only the dynamically created rows that are having the issues.

    function addNewTableRow(fileTable, fileTitle, fileName)
    		var table = getMyElement(fileTable);             
    		var rowCount = table.rows.length;
    		var row = table.insertRow(rowCount);
    		var cell0 = row.insertCell(0);
    		cell0.width = 25;
    		cell0.className = "tblTicketFilesWhite";
    		cell0["onclick"] = new Function("downloadAttachmentFile('+attachID+')");

  2. #2
    Senior Coder Logic Ali's Avatar
    Join Date
    Sep 2010
    Thanked 207 Times in 202 Posts
    This isn't the best way to do it, but it's closest to what you had:
    cell0.onclick = new Function( "downloadAttachmentFile('" + attachID + "')" );


Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts