Using the Find Functions for HTML Database Forms - The getTwoWords() Function
(Page 3 of 4 )
The find() function issues a prompt dialog box. This dialog box has only one input text control. In this control the user types in the title of the column separated by a space and then the value of the cell for the row that the search has to get. The search process needs these two values in order to get the row.
Note: if two or more consecutive rows have this same cell value, any of the rows will be displayed. To limit this, you will have to write your code so that the prompt box receives more than one column title. For simplicity I do not take that into account for this series. Here the prompt dialog box receives only one title name and the cell value.
The prompt dialog box returns the two words as a single string. The getTwoWords() function separates the string into the two separate words. As an argument it receives the string that has the two words. It returns the two words in an array. If the user typed in correctly, the first element in the array is the title and the second is the cell value. This is the function:
function getTwoWords(entry)
{
var firstWord = "";
var secondWord = "";
var i = 0;
do
{
firstWord+= entry.charAt(i);
++i;
if (i == entry.length)
break;
} while (entry.charAt(i) != " ")
if (i != entry.length)
{
++i; //take account of the space
do
{
secondWord+= entry.charAt(i);
++i;
} while (i <= (entry.length-1))
}
var tempArr = new Array(2);
tempArr[0] = firstWord;
tempArr[1] = secondWord;
return tempArr;
}
In this function there are two while loops. The first while loop extracts the first word. The second while loop extracts the second word if it was typed (that is, if while extracting the first word, the iteration of the received string was not complete). You can use Regular Expressions to achieve this. I have not used one here because many programmers still have not mastered Regular Expressions. However, I will soon be using them in my articles.
Next: The find() Function >>
More HTML Articles
More By Chrysanthus Forcha