Tabular Database Form Functions with HTML - The swap() and quickSort() Function
(Page 5 of 5 )
Here these functions have to take into consideration the fact that the recordset has Input Text Controls for each visible cell. These are the new functions:
function swap(m,n)
{
for (z=0; z<=6; z++)
{
if (z <= 5)
{
//form the Input Text Control ID for the parameter, m
IDM = "EI" + m + z;
//form the Input Text Control ID for the parameter, n
IDN = "EI" + n + z;
temp = document.getElementById(IDM).value;
document.getElementById(IDM).value = document.getElementById(IDN).value;
document.getElementById(IDN).value = temp;
}
else
{
temp = document.getElementById('Recordset').rows[m].cells[z].innerHTML;
document.getElementById('Recordset').rows[m].cells[z].innerHTML = document.getElementById('Recordset').rows[n].cells[z].innerHTML;
document.getElementById('Recordset').rows[n].cells[z].innerHTML = temp;
}
}
}
function quickSort(left,right,titleInx)
{//the function receives a recordset, indices for the left and right rows, and the index for the title column.
i = left;
j = right;
//form the Input Text Control ID for the parameter, left
IDLeft = "EI" + left + titleInx;
//form the Input Text Control ID for i
IDI = "EI" + i + titleInx;
//form the Input Text Control ID for j
IDJ = "EI" + j + titleInx;
if(document.getElementById(IDI).value > document.getElementById(IDJ).value)
{
swap(i, j);
}
do //increment i and decrement j, then swap if necessary
{
do
{
if ((i+1)<=right) //do not increment i beyond the index for the right element
{
++i; IDI = "EI" + i + titleInx;
}
} while (document.getElementById(IDI).value < document.getElementById(IDLeft).value)
do
{
if ((j-1)>=left) //do not decrement j beyond the index for the left element
{
--j; IDJ = "EI" + j + titleInx;
}
} while (document.getElementById(IDJ).value > document.getElementById(IDLeft).value)
if (i<j)
{
swap(i, j);
}
} while (i < j)
swap(j, left);
var k = j; //the pivot.
var leftLeft = left; //the index for the left element of the left sub-list, initialized
if ((k-1)>=left) //we do not want a value for k that will be less than the left index
{
var leftRight = k - 1; //the index for the right element of the left sub-list, initialized
}
if ((k+1)<=right) //we do not want a value for k that will be greater than the right index
{
var rightLeft = k + 1; //the index for the left element of the right sub-list, initialized
}
var rightRight = right; //the index for the right element of the right sub-list, initialized
//recursion for the left sub-list - only called if a left sub-list exists
if (k != left)
{
quickSort(leftLeft,leftRight,titleInx);
}
//recursion for the right sub-list - only called if a right sub-list exists
if (k != right)
{
quickSort(rightLeft,rightRight,titleInx);
}
}
The finalize()
The main aim of this function is to submit the data in the Transmitted table. The function has been modified for some of the reasons given above. This is the new function:
function finalize(ID)
{
if (ID == "Do1")
{
document.getElementById('Don1').click();
self.close(); //close the window after submit if the Done button was clicked
}
else
{
document.getElementById('Sa1').click();
}
}
In this part of the series we have not considered larger text (textarea), images and video clips. I will consider video clips in a separate article. In the next parts I will consider larger texts, images and then I will also consider the program that receives the transmitted data at the server and the program sends the web page from the server.
We continue in the next part of the series.
| DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware. |