JavaScript Fire onkeyup in generated table with contenteditable

I've got a small problem in my javascript which i am stuck on for a while now. What i did is :

  1. Create an empty table.
  2. Generate the tr/td tags and values inside the table(from JSON-object).

    for (var i = 0 ; i < myList.length ; i++) {
        var row$ = $('<tr/>');
        for (var colIndex = 0 ; colIndex < columns.length ; colIndex++) {
            var cellValue = myList[i][columns[colIndex]];
    
            if(colIndex == columns.indexOf("type")) 
            {
    
                var box$ = $('<td/>');
                if(cellValue == "Organisation")
                box$.addClass( "uk-badge uk-badge-danger" );
                else
                box$.addClass( "uk-badge uk-badge-primary" );
                box$.html(cellValue);
                row$.append(box$);
    
            } 
            else 
            { 
                var box$ = $('<td/>');
                box$.html(cellValue);
                box$.attr('contenteditable','true');
                box$.attr('onkeyup','updateJSON('+colIndex+','+i+')');
                row$.append(box$);
            }
    
    
        }
        $(selector).append(row$);
    
    }
    
  3. table looks fine:

td contenteditable="true" onkeyup="updateJSON(3,0)">Timmy/td>

The problem occurs when the table is generated and i edit a field. the 'onkeyup' does not 'fire' while it should. Replacing the 'onkeyup' with an 'onclick' works just fine. I have no clue why this does not work, can anybody help?

var myList = [
  {
    "id": 1,
    "name": "arnold"
  },
  {
    "id": 2,
    "name": "hans"
  },
  {
    "id": 3,
    "name": "jack"
  },
  {
    "id": 4,
    "name": "Peter"
  }];

	function loadDoc3() {
				$("#RelationDataTable tr").remove();
				buildHtmlTable('#RelationDataTable');
	}

	// Builds the HTML Table out of myList.
	function buildHtmlTable(selector) {
		var columns = addAllColumnHeaders(myList, selector);

		for (var i = 0 ; i < myList.length ; i++) {
			var row$ = $('<tr/>');
			for (var colIndex = 0 ; colIndex < columns.length ; colIndex++) {
				var cellValue = myList[i][columns[colIndex]];

				if(colIndex == columns.indexOf("type")) 
				{
					
					var box$ = $('<td/>');
					if(cellValue == "Organisation")
					box$.addClass( "uk-badge uk-badge-danger" );
					else
					box$.addClass( "uk-badge uk-badge-primary" );
					box$.html(cellValue);
					row$.append(box$);
					
				} 
				else 
				{ 
					var box$ = $('<td/>');
					box$.html(cellValue);
                    box$.attr('contenteditable','true');
					box$.attr('onkeyup','updateJSON('+colIndex+','+i+')');
					//box$.click(function() {
//  alert( "Handler for .keyup() called." );
//});
					row$.append(box$);
				}

				
			}
			$(selector).append(row$);
		
		}
	}
	var currentcolumns = [];


	// Adds a header row to the table and returns the set of columns.
	// Need to do union of keys from all records as some records may not contain
	// all records
	function addAllColumnHeaders(myList) {
		var columnSet = [];
		var headerTr$ = $('<tr/>');

		for (var i = 0 ; i < myList.length ; i++) {
			var rowHash = myList[i];
			for (var key in rowHash) {
				if ($.inArray(key, columnSet) == -1 && key != "id") {
					columnSet.push(key);
					headerTr$.append($('<th/>').html(key));
				}
			}
		}
		$("#RelationDataTable").append(headerTr$);
		currentcolumns = columnSet;
		return columnSet;
	}
	function updateJSON(xx,y)
	{
		var cellValue = myList[y][currentcolumns[xx]];
		alert(document.getElementById("RelationDataTable").rows[y+1].cells[xx].firstChild.nodeValue);
		myList[y][currentcolumns[xx]] = document.getElementById("RelationDataTable").rows[y+1].cells[xx].firstChild.nodeValue;
		x = 2;
	}
<head>
	<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
  </head>
<body>
<input id="searchname" type="text" name="InsertSearchname" onkeyup="loadDoc3()"><h2>Search Contact</h2>
<table id="RelationDataTable">
						<thead>
                            </thead>
                            <tbody>
                            </tbody>
						</table>
  </body>
Answer:1

I have am trying to create jQuery code which adds a active-menu class to a link whenever I click on it. However I need to check first if it already has the class before adding. I only need the link ...

I have am trying to create jQuery code which adds a active-menu class to a link whenever I click on it. However I need to check first if it already has the class before adding. I only need the link ...

On my website, I have an slider with images. In the backend, the current slider images are displayed as well as a button that adds an input field, so I can upload new images for the slider. The code ...

On my website, I have an slider with images. In the backend, the current slider images are displayed as well as a button that adds an input field, so I can upload new images for the slider. The code ...

  1. get file from form php
  2. save file from form php
  3. file itr from form 16
  4. upload file from form
  5. php file from form
  6. upload file from form php
  7. upload file from form ajax
  8. send file from form
  9. download file from form
  10. post file from form
  11. submit file from form
  12. file from html form
  13. curl file from form
  14. file form 941 online
  15. file form d
  16. file form 941
  17. file form 990-n
  18. file form 1040
  19. file form 7004 online
  20. file form 4868 online

I have the form disabled when click edit form is enable <% while(resultset.next()){ %> <form method='POST' action='EditCompany?id=<%= resultset.getString(1)%>'> <tbody> &...

I have the form disabled when click edit form is enable <% while(resultset.next()){ %> <form method='POST' action='EditCompany?id=<%= resultset.getString(1)%>'> <tbody> &...

  1. enable button when form is valid angular
  2. enable button when form is valid
  3. enable submit button when form is valid
  4. enable button if form is valid angular 6

I am using testcafe version - 1.6.1 I am trying to apply an assertion to see if an element is clickable or not (expect to not be clickable). I've found the elements class name and a dynamic sibling ...

I am using testcafe version - 1.6.1 I am trying to apply an assertion to see if an element is clickable or not (expect to not be clickable). I've found the elements class name and a dynamic sibling ...

  1. hasclass doesn't work
  2. jquery hasclass doesn't work
  3. jquery doesn't hasclass