Sorting for Database Forms with HTML - The titleBoolArr Array
(Page 4 of 4 )
This is a JavaScript two-dimensional array having two columns. The first column holds the titles (ID, Name, etc); the second holds the corresponding indices. The second column holds either a “true” or a “false” value, which indicates whether the corresponding column is sorted. The titles have been written in such a way that the recordset column indices are the corresponding row indices of the titleBoolArr array. This is the construction of the array and initialization:
var titleBoolArr = new Array(6)
for (i=0; i < 6; i++)
{
titleBoolArr[i] = new Array(2);
}
//initialize the array
titleBoolArr[0][0] = "ID"; titleBoolArr[0][1] = "false";
titleBoolArr[1][0] = "Name"; titleBoolArr[1][1] = "false";
titleBoolArr[2][0] = "Department"; titleBoolArr[2][1] = "false";
titleBoolArr[3][0] = "Job"; titleBoolArr[3][1] = "false";
titleBoolArr[4][0] = "Years"; titleBoolArr[4][1] = "false";
titleBoolArr[5][0] = "Salary"; titleBoolArr[5][1] = "false";
First a one-dimensional array is created with the line:
var titleBoolArr = new Array(6)
Next, each element of the array is made an array by the “for” loop. The two dimensional array is actually an array of arrays. JavaScript does not have a single statement for creating a two dimensional array.
The setTitleBool() Function
After sorting, this function indicates that a particular column has been sorted by setting the Boolean value for the column to “true” in the titleBoolArr array. It also indicates that no other column is sorted by setting all the other Boolean values to “false”. This is the function:
function setTitleBool(theTitle)
{
for (i=0; i<6; i++)
{
if (titleBoolArr[i][0] == theTitle)
titleBoolArr[i][1] = "true";
else
titleBoolArr[i][1] = "false";
}
}
We shall 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. |