Ti propongo questo (che ricava tutte le righe possibili per una ricerca a partire da una colonna qualsiasi)
codice:
<HTML>
<HEAD>
<TITLE>Selezione da una lista digitando i caratteri in un TextBox</TITLE>
<HEAD>
<style type="text/css">
<!--
.inverted {color:white;background-color:navy}
-->
</style>
<SCRIPT>
<!--
var previousRow = null;
var tdArray = new Array();
function find() {
//----------- Colonna da trattare
colToProcess = document.getElementById('selezionaPer').value;
//----------- Stringa da controllare
stringToFind = document.getElementById('input1').value;
stringToFind = stringToFind.toLowerCase();
//==============================================================
//----------- N° delle righe della tabella
rows = document.getElementById('stati').rows.length;
//----------- Ripristino della class delle righe
for (i=0;i<rows;i++) {
currentRow = document.getElementById('stati').rows.item(i)
currentRow.className = "";
} // for (i=0;i<rows;i++)
//==============================================================
//----------- Assegnazione di un'id in caso la cella non ne avesse
// Inserimento delle celle in un array
autoId = 0;
indexArr = 0;
for (i=0;i<rows;i++) {
currentRow = document.getElementById('stati').rows.item(i)
//------------ si assume che la colonna da controllare sia quella selezionata dalla select
controlledCell = parseInt(colToProcess);
currentCell = currentRow.cells.item(controlledCell);
if (currentCell.id == "") {
currentCell.id = "auto"+autoId;
autoId++;
} // if (currentCell.id == "")
//------------ Inserimento dell'id nell'array
tdArray[indexArr++] = currentCell.id;
} // for (i=0;i<rows;i++)
//==============================================================
//----------- Ricerca se esistono celle i cui valori cominciano per stringToFind
arrResult = new Array();
iarrResult = 0;
found = false;
for (i=stringToFind.length;i>0;i--) {
if (! found) {
for (j=0;j<tdArray.length;j++) {
currentCell = document.getElementById(tdArray[j]);
currentCellText = currentCell.innerHTML;
currentCellText = currentCellText.toLowerCase();
if (currentCellText.substr(0,i) == stringToFind.substr(0,i)) {
if (stringToFind.substr(i+1,stringToFind.length-i) >= currentCellText.substr(i+1,stringToFind.length-i)) {
arrResult[iarrResult++] = tdArray[j];
found = true;
} // if (stringToFind.substr(i+1,stringToFind.length-i) >= currentCellText.substr(i+1,stringToFind.length-i))
} // if (currentCellText.substr(0,i) == stringToFind.substr(0,i))
} // for (j=0;j<tdArray.length;j++
} // if (! found)
} // for (i=stringToFind.length;i>=0;i--)
//==============================================================
//----------- Assegnazione della classe ai td presenti nell'array
for (i=0;i<arrResult.length;i++) {
curRow = document.getElementById(arrResult[i]).parentElement;
curRow.className = "inverted";
} //
//==============================================================
//----------- Disassegnazione di un'id in caso la cella non ne avesse uno prima
for (i=0;i<rows;i++) {
currentRow = document.getElementById('stati').rows.item(i)
cells = currentRow.cells.length;
//------------ si assume che la colonna da controllare sia quella selezionata dalla select
controlledCell = parseInt(colToProcess);
for (j=0;j<cells;j++) {
currentCell = currentRow.cells.item(controlledCell);
currentCellId = currentCell.id;
if (currentCellId.substr(0,4) == "auto") {
currentCell.id = "";
} // if (currentCellId.substr(0,4) == "auto")
} // for (j=0;j<cells;j++)
} // for (i=0;i<rows;i++)
if (arrResult.length == 0) {
alert("non trovato");
return false;
} //if (arrResult.length == 0)
return true;
} // function find()
//-->
</SCRIPT>
</HEAD>
<BODY BGCOLOR="#ffffff">
<FORM NAME="modulo">
Seleziona per
<select id="selezionaPer">
<option value="0">Colonna 1</option>
<option value="1">Colonna 2</option>
</select>
<INPUT TYPE="text" NAME="input1" ID="input1" VALUE="Scrivi..." CLASS="" >
<INPUT TYPE="button" VALUE="Cerca" onclick="find()" >
<DIV ID="container"
STYLE="height:200px; width:350;z-index=100;font-family:verdana;font-size:9pt;overflow: auto;">
<TABLE id="stati" NAME="stati" BORDER="1">
<TR><TD>Albania</TD><td>diventano </td></TR>
<TR><TD>Cayman Islands</TD><td>vorrei </td></TR>
<TR><TD>Central African Rep.</TD><td>record </td></TR>
<TR><TD>Chad</TD><td>Grazie </td></TR>
<TR><TD>Chile</TD><td>blu </td></TR>
<TR><TD>China</TD><td>freccia </td></TR>
<TR><TD>Christmas Island</TD><td>cene </td></TR>
<TR><TD>Gambia</TD><td>palle </td></TR>
<TR><TD>Georgia</TD><td>diventano </td></TR>
<TR><TD>Germany</TD><td>Fattibile</td></TR>
<TR><TD>Ghana</TD><td>tempo </td></TR>
<TR><TD>Gibraltar</TD><td>occhiata</td></TR>
<TR><TD>Great Britain (UK)</TD><td>dirai</td></TR>
<TR><TD>Greece</TD><td>scriptino </td></TR>
<TR><TD>Greenland</TD><td>uccidere </td></TR>
<TR><TD>Grenada</TD><td>seguente </td></TR>
<TR><TD>Guadeloupe (Fr.)</TD><td>righe </td></TR>
<TR><TD>Guam (US)</TD><td>diventano </td></TR>
<TR><TD>Guatemala</TD><td>occhiata</td></TR>
<TR><TD>Guinea</TD><td>riga </td></TR>
<TR><TD>Guinea Bissau</TD><td>spezzate </td></TR>
<TR><TD>Guyana</TD><td>forum </td></TR>
<TR><TD>Italy</TD><td>seguente </td></TR>
<TR><TD>Ivory Coast</TD><td>occhiata</td></TR>
</TABLE>
</div>
</FORM>
<div id="o"></div>
</BODY>
</HTML>