Joe,
Thanks for that performance boost. I didn't realize that global vars in javascript were slower than local vars.
I switched the eval as well.
I figured out why only one list was populated. I needed to move to the first record, because after the first populate it statys at EOF.
The one problem I still have and it is very bizarre is the following. If I have more than one select statement in my HTML that has a DSO bound to it, only the first one appears followed by the third and after that it is erratic. However, if they are in a table the seect statements are all rendered on the page. Here is some updated code for you to see what I mean. You can also view the example at
http://www.rugbyincanada.com/test/test3.html
Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Data Binding Tests</title>
<script language="javascript">
<!--
function populateLists()
{
for(var i=1;i <= (document.forms[0].elements.length + 1);i++)
//for(var i=1;i <= 4;i++)
{
//populateSelect(eval("document.forms[0].select" + i), i);
populateSelect(document.frmBind["select" + i], i);
}
}
function populateSelect(objSelect, intIndex)
{
// Since we can't populate a list with databinding, we need to populate it option by option.
if (objSelect) {
with (objSelect)
{
options.length = 0;
var i = 0;
//Need to start at the first record because after the first lst is populated it stays at the EOF
tdcCustomer.recordset.MoveFirst();
while (!tdcCustomer.recordset.EOF)
{
options[i] = new Option(tdcCustomer.recordset.Fields("ContactName") ,tdcCustomer.recordset.Fields("CustomerID"));
i++;
tdcCustomer.recordset.MoveNext();
}
//alert("Finsished populating " + objSelect.name);
}
}
else
{
alert("Drop down list " + intIndex + " was not rendered in the page even though it exists in the HTML code. List binding aborted...");
}
}
// -->
</script>
</head>
<body onload="populateLists();">
<object classid="clsid:333C7BC4-460F-11D0-BC04-0080C7055A83" ID="tdcCustomer" HEIGHT="0" WIDTH="0" VIEWASTEXT>
<param name="DataURL" VALUE="customers.csv">
<param name="UseHeader" VALUE="True">
<param name="TextQualifier" VALUE=""">
</object>
<form id="frmBind" name="frmBind" onchange="alert(this.name);">
<p align="center"><strong>There should be 15 Dropdown Lists here (12 in the
table and 3 before the table), but in reality the 12 in the table appear,
and only Dropdown lists 1 and 3. I have no idea why 2 does not appear.</strong></p>
<p align="center">Dropdown List 1<br>
<select id="select" name="select1" datasrc="tdcCustomer" datafld="ContactName" />
</p>
<p align="center">Dropdown List 2 <br>
<select id="select16" name="select2" datasrc="tdcCustomer" datafld="ContactName" />
</p>
<p align="center">Dropdown List 3<br>
<select id="select17" name="select3" datasrc="tdcCustomer" datafld="ContactName" />
</p>
<table width="400" border="1" align="center">
<tr valign="top">
<td width="108">Dropdown List 4<br> <select id="select4" name="select4" datasrc="tdcCustomer" datafld="ContactName" />
</td>
</tr>
<tr valign="top">
<td>Dropdown List 5<br> <select id="select5" name="select5" datasrc="tdcCustomer" datafld="ContactName" />
</td>
</tr>
<tr valign="top">
<td>Dropdown List 6<br> <select id="select6" name="select6" datasrc="tdcCustomer" datafld="ContactName" />
</td>
</tr>
<tr valign="top">
<td>Dropdown List 7<br> <select id="select7" name="select7" datasrc="tdcCustomer" datafld="ContactName" />
</td>
</tr>
<tr valign="top">
<td>Dropdown List 8<br> <select id="select8" name="select8" datasrc="tdcCustomer" datafld="ContactName" />
</td>
</tr>
<tr valign="top">
<td>Dropdown List 9<br> <select id="select9" name="select9" datasrc="tdcCustomer" datafld="ContactName" />
</td>
</tr>
<tr valign="top">
<td>Dropdown List 10<br> <select id="select10" name="select10" datasrc="tdcCustomer" datafld="ContactName" />
</td>
</tr>
<tr valign="top">
<td>Dropdown List 11<br> <select id="select11" name="select11" datasrc="tdcCustomer" datafld="ContactName" />
</td>
</tr>
<tr valign="top">
<td>Dropdown List 12<br> <select id="select12" name="select12" datasrc="tdcCustomer" datafld="ContactName" />
</td>
</tr>
<tr valign="top">
<td>Dropdown List 13<br> <select id="select13" name="select13" datasrc="tdcCustomer" datafld="ContactName" />
</td>
</tr>
<tr valign="top">
<td>Dropdown List 14<br> <select id="select14" name="select14" datasrc="tdcCustomer" datafld="ContactName" />
</td>
</tr>
<tr valign="top">
<td>Dropdown List 15<br> <select id="select15" name="select15" datasrc="tdcCustomer" datafld="ContactName" />
</td>
</tr>
</table>
</form>
</body>
</html>
Quote:
quote:Originally posted by joefawcett
There are two things amiss. Firstly you declare a global variable in populateLists in your loop. You then change this value to more than three in the other function. You need to prefix it with var to make it local to the function:
Code:
for(var i=1;i<=3;i++)
and
Secondly you need to move the recordset cursor back to the start each time you use the recordset:
Code:
options.length = 0;
var i = 0;
tdcCustomer.recordset.moveFirst();
while (!tdcCustomer.recordset.EOF)
Another thing is your use of eval. The eval function is costly in terms of time and resources and is almost never needed. Just write:
Code:
populateSelect(document.frmBind[("select" + i)]);
--
Joe
|