JeniF 0 Junior Poster in Training

Hello all..I am working on a search script that I am using AJAX and dynamic html to show results within a table. based on the users search criteria, I display the results and a summary of those results as well. I allow the user to delete results by row and a function is called to refresh the search criteria and redisplay the results and summary based on the results minus the deleted row. Everything works fine on the first deletion, but if I try to delete a second row of the refreshed results, I end up with the original result set redisplaying. My code is as follows:

//initial function to display search results

function submit_createBatch_search()
{
	var orderString = orderSearchArray.join("~");
	document.getElementById("orderString").value = orderString;
	//alert(orderString);

	var location = document.getElementById('location').value;
	var chemicals = document.getElementById('chemicals').value;
	var startDate = document.getElementById('startDate').value;
	var endDate = document.getElementById('endDate').value;

	var page = "dbQuery.php?mode=getSearchData&location=" + location + "&chemicals=" + chemicals + "&startDate=" + startDate + "&endDate=" + endDate + "&orderString=" + orderString ;
	var returnData = process_AJAX(page,1);
	var resultArray =  returnData.split("||");
	//alert (resultArray);



//the table below displays the results of the search and allows the user to delete any particular row by calling the function 'submit_Resummarize_Batch_search(\""+resultArrayContent[0]+"\" --> carring the bc_id of the array

	var dataTable = document.getElementById('SearchTable');
	
	var numRows = dataTable.rows.length;
		if (numRows > 1) 
		{
			//Delete all previous data in result table
			for (var i = numRows; i > 1; i--)
			{
				var rowIndexValue = i - 1;
				dataTable.deleteRow(rowIndexValue);
			}
		}
				////ensures that there is data in the response text
				if (resultArray[0] != '')
				{
						orderResultArray.length = 0;
						for (var i = 0; i < resultArray.length -1; i++) 
						{
							var resultArrayContent = resultArray[i].split("~");
							var newRow = dataTable.insertRow(-1); 
							var ID = newRow.insertCell(0);
							var bc_id = newRow.insertCell(1);
							var location = newRow.insertCell(2);
							var releaseDate = newRow.insertCell(3);
							var chemical = newRow.insertCell(4);
							var uom = newRow.insertCell(5);
							var carrier = newRow.insertCell(6);
							var grower = newRow.insertCell(7);
							var farm = newRow.insertCell(8);
							var field = newRow.insertCell(9);
							var rowID = i + 1;
							ID.innerHTML="<img src= '../images/delete.gif' onClick='submit_Resummarize_Batch_search(\""+resultArrayContent[0]+"\");'/>";
							bc_id.innerHTML=resultArrayContent[0];
							location.innerHTML=resultArrayContent[1];
							releaseDate.innerHTML=resultArrayContent[2];
							chemical.innerHTML=resultArrayContent[3];
							uom.innerHTML=resultArrayContent[4];
							carrier.innerHTML=resultArrayContent[8];
							grower.innerHTML=resultArrayContent[5];
							farm.innerHTML=resultArrayContent[6];
							field.innerHTML=resultArrayContent[7];
							field.innerHTML=resultArrayContent[9];
							orderResultArray.push(resultArrayContent[0]);
						}
				}
////////the following table displays the summary results of the above table

var BatchTable = document.getElementById('BatchSummary');
	
	var numRows = BatchTable.rows.length;
		if (numRows > 1) 
		{
			//Delete all previous data in result table
			for (var i = numRows; i > 1; i--)
			{
				var rowIndexValue = i - 1;
				BatchTable.deleteRow(rowIndexValue);
			}
		}
				////ensures that there is data in the response text
				if (resultArray[0] != '') 
				{
						
						for (var i = 0; i < resultArray.length -1; i++) 
						{
							var resultArrayContent = resultArray[i].split("~");
							var newRow = BatchTable.insertRow(-1); 
							var Title = newRow.insertCell(0);
							var blankA = newRow.insertCell(1);
							var blankB = newRow.insertCell(2);
							var blankC = newRow.insertCell(3);
							var blankF = newRow.insertCell(4);
							var blankAA = newRow.insertCell(5);
								Title.innerHTML="<B>Batch Summary</B>";
								blankA.innerHTML="";  
								blankB.innerHTML="";
								blankC.innerHTML="";
								blankF.innerHTML="";
								blankAA.innerHTML="";
								
							var newRow2 = BatchTable.insertRow(-1); 
							var ChemicalLabel = newRow2.insertCell(0);
							var Chemical = newRow2.insertCell(1);
							var blankG = newRow2.insertCell(2);
							var BatchLabel = newRow2.insertCell(3);
							var Batch = newRow2.insertCell(4);
								ChemicalLabel.innerHTML="Product:";
								Chemical.innerHTML=resultArrayContent[3];
								blankG.innerHTML="";
								BatchLabel.innerHTML="Batch Name:";
								Batch.innerHTML="<input name=\"batch\" type=\"text\" size=\"30\" maxlength=\"25\" />";
							
							var newRow3 = BatchTable.insertRow(-1); 
							var AmountLabel = newRow3.insertCell(0);
							var Amount = newRow3.insertCell(1);
							var blankH = newRow3.insertCell(2);
							var PilotLabel = newRow3.insertCell(3);
							var Pilot = newRow3.insertCell(4);
								AmountLabel.innerHTML="Amount:";
								Amount.innerHTML=resultArrayContent[10];
								blankH.innerHTML="";
								PilotLabel.innerHTML="Pilot:";
								Pilot.innerHTML="<select name=\"pilot\"><option>Chris Haak</option> </select>";
							
							var newRow4 = BatchTable.insertRow(-1); 
							var blankD = newRow4.insertCell(0);
							var blankE = newRow4.insertCell(1);
							var blankBB = newRow4.insertCell(2);
							
							var MixingLabel = newRow4.insertCell(3);
							var MixingLocation = newRow4.insertCell(4);
								blankD.innerHTML="";
								blankE.innerHTML="";
								blankBB.innerHTML="";
								
								MixingLabel.innerHTML="Junge Mixing Location:";
								MixingLocation.innerHTML="<select name=\"mixingLocation\"><option>Virden</option> <option>Lincoln</option></select>";
							
							var newRow5 = BatchTable.insertRow(-1); 
							var CarrierLabel = newRow5.insertCell(0);
							var Carrier = newRow5.insertCell(1);
							var blank1 = newRow5.insertCell(2);
							var blank2 = newRow5.insertCell(3);
								CarrierLabel.innerHTML="Carrier:";
								Carrier.innerHTML=resultArrayContent[8];
								blank1.innerHTML="";
								blank2.innerHTML="";
								
							var newRow6 = BatchTable.insertRow(-1); 
							var CAmountLabel = newRow6.insertCell(0);
							var CarrierAmount = newRow6.insertCell(1);
							var blank3 = newRow6.insertCell(2);
							var blank4 = newRow6.insertCell(3);
								CAmountLabel.innerHTML="Amount:";
								CarrierAmount.innerHTML=resultArrayContent[11];
								blank3.innerHTML="";
								blank4.innerHTML="";
							
							
						//alert(resultArray.length);
					}

							var newRow7 = BatchTable.insertRow(-1);
							var blank5 = newRow7.insertCell(0);
							var blank6 = newRow7.insertCell(1);
							var Save = newRow7.insertCell(2);
							var Cancel = newRow7.insertCell(3);
								blank5.innerHTML="";
								blank6.innerHTML="";
								Save.innerHTML="<button type=button name=\"Save\" onClick=\"save_Batch();\">Save</button>";
								Cancel.innerHTML="<button type=button name=\"Cancel\" onClick=\"cancel_Batch();\">Cancel</button>";
					}
}///end of function for search results

///the following function resummarizes and redisplays the results after the user deletes one of the search results



	
function submit_Resummarize_Batch_search(deleteOrderId)
{
	for (var i=0; i<orderResultArray.length; i++) {
		if (deleteOrderId == orderResultArray[i]) {
			orderResultArray.splice(i,1);
		}
	}
	
	var orderString = orderResultArray.join("~");
	document.getElementById("orderString").value = orderString;
	//alert(orderString);

	var page = "dbQuery.php?mode=getSearchData&orderString=" + orderString;
	var returnData = process_AJAX(page,1);
	var resultArray =  returnData.split("||");
	//alert (resultArray);

/// redisplaying the search results after deleting a row
	var dataTable = document.getElementById('SearchTable');
	
	var numRows = dataTable.rows.length;
		if (numRows > 1) 
		{
			//Delete all previous data in result table
			for (var i = numRows; i > 1; i--)
			{
				var rowIndexValue = i - 1;
				dataTable.deleteRow(rowIndexValue);
			}
		}
				////ensures that there is data in the response text
				if (resultArray[0] != '') 
				{
						orderResultArray.length = 0;
						for (var i = 0; i < resultArray.length -1; i++) 
						{
							var resultArrayContent = resultArray[i].split("~");
							var newRow = dataTable.insertRow(-1); 
							var ID = newRow.insertCell(0);
							var bc_id = newRow.insertCell(1);
							var location = newRow.insertCell(2);
							var releaseDate = newRow.insertCell(3);
							var chemical = newRow.insertCell(4);
							var uom = newRow.insertCell(5);
							var carrier = newRow.insertCell(6);
							var grower = newRow.insertCell(7);
							var farm = newRow.insertCell(8);
							var field = newRow.insertCell(9);
							var rowID = i + 1;
							ID.innerHTML="<img src= '../images/delete.gif' onClick='submit_Resummarize_Batch_search("+resultArrayContent[0]+");'/>";
							bc_id.innerHTML=resultArrayContent[0];
							location.innerHTML=resultArrayContent[1];
							releaseDate.innerHTML=resultArrayContent[2];
							chemical.innerHTML=resultArrayContent[3];
							uom.innerHTML=resultArrayContent[4];
							carrier.innerHTML=resultArrayContent[8];
							grower.innerHTML=resultArrayContent[5];
							farm.innerHTML=resultArrayContent[6];
							field.innerHTML=resultArrayContent[7];
							field.innerHTML=resultArrayContent[9];
						//alert(resultArray.length);
						}
				}
////////this redisplays the summary results after the users deletes a row

var BatchTable = document.getElementById('BatchSummary');
	
	var numRows = BatchTable.rows.length;
		if (numRows > 1) 
		{
			//Delete all previous data in result table
			for (var i = numRows; i > 1; i--)
			{
				var rowIndexValue = i - 1;
				BatchTable.deleteRow(rowIndexValue);
			}
		}
				////ensures that there is data in the response text
				if (resultArray[0] != '') 
				{
						
						for (var i = 0; i < resultArray.length -1; i++) 
						{
							var resultArrayContent = resultArray[i].split("~");
							var newRow = BatchTable.insertRow(-1); 
							var Title = newRow.insertCell(0);
							var blankA = newRow.insertCell(1);
							var blankB = newRow.insertCell(2);
							var blankC = newRow.insertCell(3);
							var blankF = newRow.insertCell(4);
							var blankAA = newRow.insertCell(5);
								Title.innerHTML="<B>Batch Summary</B>";
								blankA.innerHTML="";  
								blankB.innerHTML="";
								blankC.innerHTML="";
								blankF.innerHTML="";
								blankAA.innerHTML="";
								
							var newRow2 = BatchTable.insertRow(-1); 
							var ChemicalLabel = newRow2.insertCell(0);
							var Chemical = newRow2.insertCell(1);
							var blankG = newRow2.insertCell(2);
							var BatchLabel = newRow2.insertCell(3);
							var Batch = newRow2.insertCell(4);
								ChemicalLabel.innerHTML="Product:";
								Chemical.innerHTML=resultArrayContent[3];
								blankG.innerHTML="";
								BatchLabel.innerHTML="Batch Name:";
								Batch.innerHTML="<input name=\"batch\" type=\"text\" size=\"30\" maxlength=\"25\" />";
							
							var newRow3 = BatchTable.insertRow(-1); 
							var AmountLabel = newRow3.insertCell(0);
							var Amount = newRow3.insertCell(1);
							var blankH = newRow3.insertCell(2);
							var PilotLabel = newRow3.insertCell(3);
							var Pilot = newRow3.insertCell(4);
								AmountLabel.innerHTML="Amount:";
								Amount.innerHTML=resultArrayContent[10];
								blankH.innerHTML="";
								PilotLabel.innerHTML="Pilot:";
								Pilot.innerHTML="<select name=\"pilot\"><option>Chris Haak</option> </select>";
							
							var newRow4 = BatchTable.insertRow(-1); 
							var blankD = newRow4.insertCell(0);
							var blankE = newRow4.insertCell(1);
							var blankBB = newRow4.insertCell(2);
							
							var MixingLabel = newRow4.insertCell(3);
							var MixingLocation = newRow4.insertCell(4);
								blankD.innerHTML="";
								blankE.innerHTML="";
								blankBB.innerHTML="";
								
								MixingLabel.innerHTML="Junge Mixing Location:";
								MixingLocation.innerHTML="<select name=\"mixingLocation\"><option>Virden</option> <option>Lincoln</option></select>";
							
							var newRow5 = BatchTable.insertRow(-1); 
							var CarrierLabel = newRow5.insertCell(0);
							var Carrier = newRow5.insertCell(1);
							var blank1 = newRow5.insertCell(2);
							var blank2 = newRow5.insertCell(3);
								CarrierLabel.innerHTML="Carrier:";
								Carrier.innerHTML=resultArrayContent[8];
								blank1.innerHTML="";
								blank2.innerHTML="";
								
							var newRow6 = BatchTable.insertRow(-1); 
							var CAmountLabel = newRow6.insertCell(0);
							var CarrierAmount = newRow6.insertCell(1);
							var blank3 = newRow6.insertCell(2);
							var blank4 = newRow6.insertCell(3);
								CAmountLabel.innerHTML="Amount:";
								CarrierAmount.innerHTML=resultArrayContent[11];
								blank3.innerHTML="";
								blank4.innerHTML="";
							
							
						//alert(resultArray.length);
					}

var newRow7 = BatchTable.insertRow(-1);
							var blank5 = newRow7.insertCell(0);
							var blank6 = newRow7.insertCell(1);
							var Save = newRow7.insertCell(2);
							var Cancel = newRow7.insertCell(3);
								blank5.innerHTML="";
								blank6.innerHTML="";
								Save.innerHTML="<button type=button name=\"Save\" onClick=\"save_Batch();\">Save</button>";
								Cancel.innerHTML="<button type=button name=\"Cancel\" onClick=\"cancel_Batch();\">Cancel</button>";

			}


}///end of function for search results

I need the function submit_Resummarize_Batch_search(\""+resultArrayContent[0]+"\" to work each time the users deletes a row, not just on the first pass...

any suggestions/help would be greatly appreciated...........