Below is the code I have which simulates an Access list box by using Javascript and "faking" the listbox by using an html table instead.
My Questions:
Is there a way I can further simulate the Access listbox feature by having the html table scroll to a cell (the first cell, which is the name of an employee) and select that cell?
And if that technique is possible, once that letter is typed again, can it also go to the next employee whose first name also starts with that letter (if there is a next one)?
Again, I just want to do this based on the first letter that's in the first cell of a row.
I know my question is probably very unusual and maybe not even possible for a solution, but I'm working on an HTA project which uses this very useful Javascript code and I just wanted to make the listbox easier to navigate since there are a lot of employees in my department.
I appreciate any help that can be given. And if you ahve any questions, just let me know. Thanks!
My Questions:
Is there a way I can further simulate the Access listbox feature by having the html table scroll to a cell (the first cell, which is the name of an employee) and select that cell?
And if that technique is possible, once that letter is typed again, can it also go to the next employee whose first name also starts with that letter (if there is a next one)?
Again, I just want to do this based on the first letter that's in the first cell of a row.
I know my question is probably very unusual and maybe not even possible for a solution, but I'm working on an HTA project which uses this very useful Javascript code and I just wanted to make the listbox easier to navigate since there are a lot of employees in my department.
I appreciate any help that can be given. And if you ahve any questions, just let me know. Thanks!
Code:
<HTML>
<HEAD>
<script language="JavaScript">
var highlight = "#000066";
var aSelected = new Array;
function setRow(obj)
{
//Reset all rows
var rows = document.getElementsByTagName("tr");
for (var i = 0; i < rows.length; i++){
rows[i].style.backgroundColor = "";
rows[i].style.color = "black"; // <----------
}
//Highlight the selected row
if (obj.style.backgroundColor == "#000066")
obj.style.backgroundColor = "white";
else
obj.style.backgroundColor = highlight;
obj.style.Color = "white";
if (obj.style.backgroundcolor = "#000066")
obj.style.color="#ffffff";
document.getElementById("ID").value = obj.getElementsByTagName('td')[2].innerHTML;
}
function DemoAccess()
{
var oConn, oRs, sSQL, sConnectionString;
oConn = new ActiveXObject("ADODB.Connection")
sConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source='R:/Scott/Databases/New.mdb';User Id=admin;Password=;"
oConn.Open(sConnectionString)
sSQL = "SELECT tblEmployees.EmployeeName, tblEmployees.Extension, tblEmployees.UserID FROM tblEmployees ORDER BY tblEmployees.EmployeeName;"
oRs = oConn.Execute(sSQL)
PrepareTableHTML("<table border=0 cellspacing=0 cellpadding=0 width=325px;>")
PrepareTableHTML("\n")
PrepareTableHTML("<tr onclick='setRow(this);'>")
for (i = 0 ; i < oRs.Fields.Count ; i++)
PrepareTableHTML("</tr>")
PrepareTableHTML("\n")
while (! oRs.EOF)
{
PrepareTableHTML("<tr onclick='setRow(this);'>")
for (i = 0 ; i < oRs.Fields.Count ; i++)
{
PrepareTableHTML("<td>")
PrepareTableHTML(NullToNull(oRs.Fields(i).Value))
PrepareTableHTML("</td>")
}
PrepareTableHTML("</tr>")
PrepareTableHTML("\n")
oRs.MoveNext()
}
PrepareTableHTML("</table>")
PrepareTableHTML("\n")
oRs.Close()
oConn.Close()
WriteTableHTMLToDiv()
oConn = null
oRs = null
}
var TableHTML = "";
function PrepareTableHTML(sString)
{
TableHTML += sString;
}
function WriteTableHTMLToDiv()
{
document.getElementById("MyDiv").innerHTML = TableHTML;
}
function NullToNull(sValIn)
{
var sValOut, sNull
sNull = "<font color=lightgrey>Null</font>";
if (sValIn == null)
{
sValOut = sNull;
}
else
{
sValOut = sValIn
}
return sValOut
}
</script>
</HEAD>
<BODY onload="DemoAccess()">
<div style="overflow-X:hidden;overflow-Y:auto;height:85px;width:246px;border: #000000 solid 2px;">
<div id="MyDiv">
</div>
</div>
<input type="hidden" id="ID" /></span>
</BODY>
</HTML>