From: ekkehard.horner on
Dave "Crash" Dummy schrieb:
> Given a starting table object like <table id="tbl"></table> in the body of
> a HTML or HTA page, I can later use script to fill it with rows and cells:
>
> <script type="text/vbs">
> for r=0 to rows-1
> tbl.insertRow
> for c=0 to cells-1
> tbl.rows(r).insertCell
> next
> next
> </script>
>
> I would like to go further and use script to include onClick=someFunc()
> in a cell, as if it were written <td onClick=someFunc()>.
[...]
Use the elms/objects returned from the .insert* *functions*
and .attachEvent:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<hta:application id = "DynTable2"
>
<title>DynTable2</title>
<meta http-equiv = "content-type" content="text/html;
charset=iso-8859-1">
<meta http-equiv = "content-script-type" content = "text/vbscript">
<style type = "text/css">
.stdBtt
{ width: 80;
}
.Meta
{ color: red;
}
</style>
<script language = "VBScript"
type = "text/vbscript"
>
'<![CDATA[

''= create/fills table tblDyn
'
============================================================================
Function doIt()
Const cnRows = 4
Const cnCols = 3
Dim nRow
For nRow = 1 to cnRows
Dim oRow : Set oRow = tblDyn.insertRow()
Dim nCol
For nCol = 1 to cnCols
Dim oCell : Set oCell = oRow.insertCell()
oCell.Id = "R" & nRow & "C" & nCol
oCell.innerText = oCell.Id
oCell.attachevent "onclick", GetRef( "WhoAmI" )
Next
Next
End Function

''= identify elm
'
============================================================================
Sub WhoAmI( oEv )
MsgBox "I'm " & oEv.srcElement.Id
End Sub

''= attachevent sample
'
============================================================================
Sub onLoadBody
document.getElementById( "bttDoIt" ).attachevent "onclick", GetRef(
"doIt" )
End Sub

''= refreshes the HTA page, which includes re-running any Windows_Onload
code
'
============================================================================
Sub reloadHTA()
location.reload True
End Sub

']]>
</script>
</head>
<body onload = "onLoadBody">
<form>
<hr>
<table id = "tblDyn" border = "1">
</table>
<hr>
<input id = "bttDoIt" class = "StdBtt" type = "BUTTON" value = "doIt">
<hr>
<input class = "StdBtt Meta" type = "BUTTON" value = "reload"
onclick = "reloadHTA">
</form>
</body>
</html>

From: ekkehard.horner on
Dave "Crash" Dummy schrieb:
> Thank you both very much. So much to learn, so few brain cells!
You are welcome. WRT your current problem - you know the remedy:

For n = 1 To 99999999999999999999999
brain.insertCell
Next
From: "Dave "Crash" Dummy" on
ekkehard.horner wrote:
> Dave "Crash" Dummy schrieb:
>> Thank you both very much. So much to learn, so few brain cells!
> You are welcome. WRT your current problem - you know the remedy:
>
> For n = 1 To 99999999999999999999999
> brain.insertCell
> Next

Fatal error. Out of memory.

Surprising feature of the code you posted. The "onclick" element is
case sensitive! I am used to writing "onClick" for that event, but if I
enter
oCell.attachevent "onClick", GetRef( "WhoAmI" ) instead of
oCell.attachevent "onclick", GetRef( "WhoAmI" ) it doesn't work.
Drove me nuts figuring out what I was doing wrong. I thought
VBS wasn't case sensitive!

--
Crash

One man's weed is another man's wildflower.
From: Tom Lavedas on
On Sep 21, 6:16 pm, "Dave \"Crash\" Dummy" <inva...(a)invalid.invalid>
wrote:
> ekkehard.horner wrote:
> > Dave "Crash" Dummy schrieb:
> >> Thank you both very much. So much to learn, so few brain cells!
> > You are welcome. WRT your current problem - you know the remedy:
>
> >   For n = 1 To 99999999999999999999999
> >       brain.insertCell
> >   Next
>
> Fatal error. Out of memory.
>
> Surprising feature of the code you posted. The "onclick" element is
> case sensitive! I am used to writing "onClick" for that event, but if I
> enter
> oCell.attachevent "onClick", GetRef( "WhoAmI" ) instead of
> oCell.attachevent "onclick", GetRef( "WhoAmI" )  it doesn't work.
> Drove me nuts figuring out what I was doing wrong. I thought
> VBS wasn't case sensitive!
>
> --
> Crash
>
> One man's weed is another man's wildflower.

VBS is not, but the DHTML functions can be.
_____________________
Tom Lavedas
From: "Dave "Crash" Dummy" on
Tom Lavedas wrote:
> On Sep 21, 6:16 pm, "Dave \"Crash\" Dummy" <inva...(a)invalid.invalid>
> wrote:
>> Surprising feature of the code you posted. The "onclick" element is
>> case sensitive! I am used to writing "onClick" for that event, but if I
>> enter
>> oCell.attachevent "onClick", GetRef( "WhoAmI" ) instead of
>> oCell.attachevent "onclick", GetRef( "WhoAmI" ) it doesn't work.
>> Drove me nuts figuring out what I was doing wrong. I thought
>> VBS wasn't case sensitive!
>
> VBS is not, but the DHTML functions can be.

Well, when I manually enter "onClick" in a tag, that is how I enter it,
and it always works. That is why I did that here. Depending on where
you look, it is either onclick, onClick, or OnClick:
http://social.msdn.microsoft.com/Search/en-us?query=onclick
Doesn't seem fair, somehow. :-)
--
Crash

"It is not necessary to change. Survival is not mandatory."
~ W. Edwards Deming ~