Jump to content

dynamically generate table with functions for each row


cleary1981

Recommended Posts

hi,

 

I have dynamically created a table of records from my database. What I want to do now is to add some functions to each row. Similar to the delete, amend in phpMyadmin beside each record. does anyone have an example of how this can be done. I have included my javascript. Please bare in mind the code I have in the price icon and view icon part doesnt work but you can probably see what I am trying to achieve here.

 

function updateCompleteProjects() {
//alert(request.readyState);
if (request.readyState == 4) {
	//alert("");
	var returned = request.responseText;
	//alert("");
	var splitResult = returned.split("^");
		for (var i=0;i<splitResult.length-1;i++) {
		var record = splitResult[i];
		// alert(record);
		var splitRecord = record.split("$");
		var tbl = document.getElementById('panels');
		var lastRow = tbl.rows.length;
		var iteration = lastRow;
  			var row = tbl.insertRow(lastRow);
  			
  			// cell number
  			var cellLeft = row.insertCell(0);
  			var textNode = document.createTextNode(iteration);
  			cellLeft.appendChild(textNode);
  			
  			// company
  			var cellcomp = row.insertCell(1);
  			var t_comp = document.createTextNode(splitRecord[0]);
  			cellcomp.appendChild(t_comp);
  			
  			// project
  			var cellproj = row.insertCell(2);
  			var t_proj = document.createTextNode(splitRecord[1]);
  			cellproj.appendChild(t_proj);
  			
  			// project id
  			var cellprojid = row.insertCell(3);
  			var t_projid = document.createTextNode(splitRecord[2]);
  			cellprojid.appendChild(t_projid);
  			
  			// price icon
  			var cellprice = row.insertCell(4);
  			var newObject1 = document.createElement('div');
    		var price = document.createElement("img");
  			price.src="price.png";
		newObject1.appendChild(price);
		price.alt = "Price";
  			cellprice.appendChild(newObject1);
  			
  			// view icon
  			var cellview = row.insertCell(5);
  			var newObject = document.createElement('div');
  			newObject.Class ="view";
  			var ele = document.getElementsByTagName('div');
  			var view = document.createElement("img");
  			view.src="view.gif";
  			view.alt = "View";

		newObject.appendChild(view);
  	
	}
	getIncompleteProjects();
}

}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.