jaycastr 0 Light Poster

Hello All,

I am Writing a code that adds a row of cell(with inputs in them) to the table. But I want the user to complete each cell before adding a new row. I was attempting you use a for statement to go through each of the cells to check if it = "" and to alert them to complete all the fields. Im stuck and cant get it. Any help is greatly appreciated.

function addRow(tableID) {
            
        var table = document.getElementById(tableID);

	var rowCount = table.rows.length;
	var row = table.insertRow(rowCount);

	var colCount = table.rows[0].cells.length;

			
		for (var i=0, i<colCount; i++) {
			if (table.rows[rowCount].cells[i].innerHTML ="")
			{
			alert("All Fields must be complete");
			}
		}
		
			
			for(var i=0; i<colCount; i++) {

			var newcell	= row.insertCell(i);

			newcell.innerHTML = table.rows[1].cells[i].innerHTML;
			//alert(newcell.childNodes);
			switch(newcell.childNodes[0].type) {
				case "text":
					newcell.childNodes[0].type ="button";
					break;
			          case "checkbox":
					newcell.childNodes[0].checked = false;
					break;
				case "select-one":
				        newcell.childNodes[0].selectedIndex = 0;
					break;
				case "":
					newcell.childNodes[0].value = "";
					break;
				}
			}
        }
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.