Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

HTA: Fill HTML table with data dynamically? 1

Status
Not open for further replies.

mapman04

IS-IT--Management
Mar 28, 2002
158
US
I have an HTA where I'm trying to fill a HTML table with data pulled from a database. I can fill the table if I address each cell individually. Is it possible to populate the table with a Do While Loop? The dataset can be from 1 to 12 records. I've searched and haven't found any examples. Is there an easy way to do this or can't it be done in a HTA?

Thanks!
 
you can place a vb script inside your html file to access the dababase, read records based on an sql query and loop through the records in the record set, and then load any table that you want.
this code below is an example that accesses dta from an access database, loops through the records and prints each line of the database table. you can modify it to put values in some table while it's looping through the data.
here's the code:

<SCRIPT LANGUAGE="VBScript">

Option Explicit

'Sub cmdDisplay_OnClick
dim strtext, i, county, zz, startpos
Dim Message
dim eachline
dim crlf
Dim TABSPACE
dim objConnection
dim objRecordset
dim adOpenStatic
dim adLockOptimistic

adOpenStatic = 3
adLockOptimistic = 3

CRLF = Chr(13) & Chr(10)
TABSPACE = Chr(9)

Set objConnection = CreateObject("ADODB.Connection")
Set objRecordSet = CreateObject("ADODB.Recordset")

objConnection.Open _
"Provider= Microsoft.Jet.OLEDB.4.0; " & _
"Data Source=c:\myfolder\my_database.mdb"

objRecordSet.Open "SELECT * FROM some_table", objConnection, adOpenStatic, adLockOptimistic

objRecordSet.MoveFirst


Do Until objRecordSet.EOF
each_line = objRecordset.Fields.Item("data_field")

document.write eachline

objRecordset.MoveNext

Loop


</SCRIPT>


 
tsuji's suggestion is a cleaner and more compact idea, if you can construct the needed tags, etc.
 
I tried to translate the JScript to vbScript. I get an error when I try to run it. Here's the code:

cnter = 0

For intTbl = 0 To document.all.shp.rows.length
For intCel = 0 To document.all.shp.rows(intTbl).cells.length
document.all.shp.rows(intTbl).cells(intCel).innerText = cnter
cnter = cnter + 1
intCel = intCel + 1
Next
intTbl = intTbl + 1
Next


<Table Name="Shipping" ID="shp">
<TR ID = "shp01">
<TD><Div ID = "lblshp01A"></Div></TD>
<TD><Div ID = "lblshp01B"></Div></TD>
</TR>
<TR ID = "shp02">
<TD><Input Type = "Text" Name="txtshpA02" ID=101/></TD>
<TD><Input Type = "Text" Name="txtshpB02" ID=102/></TD>
</TR>
<TR ID = "shp03">
<TD><Input Type = "Text" Name="txtshpA03" ID=201/></TD>
<TD><Input Type = "Text" Name="txtshpB03" ID=202/></TD>
</TR>
</Table>
 
At least change these?

[tt]For intTbl = 0 To document.all.shp.rows.length[red]-1[/red]
For intCel = 0 To document.all.shp.rows
(intTbl).cells.length[red]-1[/red]
[/tt]
 
Also of course you don't increase indices like that!!!
[tt] intCel = intCel + 1
intTbl = intTbl + 1
[/tt]
 
tsuji:

Thank you for your expertise. Making those changes worked!

Best Regards,

mapman04
 
Is it possible to get the values of a text box that's inside the table without explictly naming the text Box? In my table I dynamically insert data and then the user inputs some other data into the text boxes in the table. I can pull the data out of the text box using "strQT = fldshpE02.Value" but I'd like to do it via a For Next loop. Can this be done? Here's a table row of the table in question. The first three cells have innertext values. Thanks!

<TR ID = "shp02">
<TD><Input Type = "Text" Name="fldshpA02" ID=101/></TD>
<TD><Input Type = "Text" Name="fldshpB02" ID=102/></TD>
<TD><Input Type = "Text" Name="fldshpC02" ID=103/></TD>
<TD><Input Type = "Radio" Name="fldshpD02" ID=104/></TD>
<TD><Input Type = "Text" Name="fldshpE02" ID=105 STYLE="width:75px"/></TD>
<TD><Input Type = "Text" Name="fldshpF02" ID=106 STYLE="width:75px"/></TD>
<TD><Input Type = "Text" Name="fldshpG02" ID=107 STYLE="width:75px"/></TD>
<TD><Input Type = "Text" Name="fldshpH02" ID=108 STYLE="width:75px"/></TD>
 
Let's say otd is the reference to a particular td element and you want to find the text box(es) within that particular td element. (It is one of those, you know, .rows(i).cells(j) thing.) Then the loop is this.
[tt]
set cinput=otd.getElementsByTagName("input")
for i=0 to cinput.length-1
if cinput(i).type="text" then
'you find the text box
svalue=cinput(i).value 'the desired value
'do thing with it
end if
next
[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top