Discussion:
Retrieving row and cell information
(too old to reply)
Dave "Crash" Dummy
2014-09-27 14:11:42 UTC
Permalink
The code below is a simplified version of code I use to edit cell
content in a table. It works fine. I can change style, text, whatever.
What I would like to do is read the row and cell location. My fantasy
code would read something like "r=obj.row.number" and "c=obj.cell.number."
Is there such a thing in the real world?

'---------------------------------- Demo.hta
--------------------------------------------
<HTA:APPLICATION ID="oHTA" APPLICATIONNAME="Demo" WindowState="maximize">
<html><body>
<TABLE id="tbl" border=1>
<TR><TD onClick="hilite(this)">Text</TD><TD
onClick="hilite(this)">Text</TD></TR>
<TR><TD onClick="hilite(this)">Text</TD><TD
onClick="hilite(this)">Text</TD></TR>
</TABLE>
</body>
<script type="text/vbs">
sub hilite(obj)
if obj.style.fontWeight="bold" then
obj.style.fontWeight="normal"
else
obj.style.fontWeight="bold"
end if
end sub
</script>
</html>
--
Crash

"The fewer the facts, the stronger the opinion."
~ Arnold H. Glasow ~
Evertjan.
2014-09-27 15:14:49 UTC
Permalink
Post by Dave "Crash" Dummy
The code below is a simplified version of code I use to edit cell
content in a table. It works fine. I can change style, text, whatever.
What I would like to do is read the row and cell location. My fantasy
code would read something like "r=obj.row.number" and "c=obj.cell.number."
Is there such a thing in the real world?
'---------------------------------- Demo.hta
--------------------------------------------
<HTA:APPLICATION ID="oHTA" APPLICATIONNAME="Demo" WindowState="maximize">
<html><body>
<TABLE id="tbl" border=1>
<TR><TD onClick="hilite(this)">Text</TD><TD
onClick="hilite(this)">Text</TD></TR>
<TR><TD onClick="hilite(this)">Text</TD><TD
onClick="hilite(this)">Text</TD></TR>
</TABLE>
</body>
<script type="text/vbs">
sub hilite(obj)
if obj.style.fontWeight="bold" then
obj.style.fontWeight="normal"
else
obj.style.fontWeight="bold"
end if
end sub
</script>
</html>
try this, or something like it:

function hilite(obj)
MsgBox(obj.parentNode.rowIndex & "-" & obj.cellIndex)
end function

Cannot test this on IE11 without messing things up.
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Dave "Crash" Dummy
2014-09-27 18:21:03 UTC
Permalink
Post by Evertjan.
Post by Dave "Crash" Dummy
The code below is a simplified version of code I use to edit cell
content in a table. It works fine. I can change style, text, whatever.
What I would like to do is read the row and cell location. My fantasy
code would read something like "r=obj.row.number" and "c=obj.cell.number."
Is there such a thing in the real world?
'---------------------------------- Demo.hta
--------------------------------------------
<HTA:APPLICATION ID="oHTA" APPLICATIONNAME="Demo" WindowState="maximize">
<html><body>
<TABLE id="tbl" border=1>
<TR><TD onClick="hilite(this)">Text</TD><TD
onClick="hilite(this)">Text</TD></TR>
<TR><TD onClick="hilite(this)">Text</TD><TD
onClick="hilite(this)">Text</TD></TR>
</TABLE>
</body>
<script type="text/vbs">
sub hilite(obj)
if obj.style.fontWeight="bold" then
obj.style.fontWeight="normal"
else
obj.style.fontWeight="bold"
end if
end sub
</script>
</html>
function hilite(obj)
MsgBox(obj.parentNode.rowIndex & "-" & obj.cellIndex)
end function
That works. Just gotta know the right words. :-)

Thanks!
Post by Evertjan.
Cannot test this on IE11 without messing things up.
I don't understand that. I am using IE11, and the code works as HTML from
a server (http://domainname/demo.htm) and as a HTA file (mshta.exe).
HTML won't
work directly from Explorer (file:///demo.htm) because of security
restrictions.
--
Crash

No government is valid that denies people the right to leave.
Dave "Crash" Dummy
2014-09-27 18:52:12 UTC
Permalink
Post by Dave "Crash" Dummy
I don't understand that. I am using IE11, and the code works as HTML
from a server (http://domainname/demo.htm) and as a HTA file
(mshta.exe). HTML won't work directly from Explorer
(file:///demo.htm) because of security restrictions.
P.S. It works from a local intranet server with sufficiently loose
script allowance. HTA is really the way to go for in house use, which is
my interest.
--
Crash

"When you get to a fork in the road, take it."
~ Yogi Berra ~
Evertjan.
2014-09-27 20:45:55 UTC
Permalink
Post by Dave "Crash" Dummy
Post by Dave "Crash" Dummy
I don't understand that. I am using IE11, and the code works as HTML
from a server (http://domainname/demo.htm) and as a HTA file
(mshta.exe). HTML won't work directly from Explorer
(file:///demo.htm) because of security restrictions.
P.S. It works from a local intranet server with sufficiently loose
script allowance. HTA is really the way to go for in house use, which is
my interest.
Yes, I tried the hta later, and it worked fine.

Still, sorry in this NG, but I like to do my clientside programming in
Javascript, and my serverside coding in VBS. No special reason for the
latter.
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Dave "Crash" Dummy
2014-09-27 21:58:02 UTC
Permalink
Post by Evertjan.
Post by Dave "Crash" Dummy
Post by Dave "Crash" Dummy
I don't understand that. I am using IE11, and the code works as
HTML from a server (http://domainname/demo.htm) and as a HTA file
(mshta.exe). HTML won't work directly from Explorer
(file:///demo.htm) because of security restrictions.
P.S. It works from a local intranet server with sufficiently loose
script allowance. HTA is really the way to go for in house use,
which is my interest.
Yes, I tried the hta later, and it worked fine.
Still, sorry in this NG, but I like to do my clientside programming
in Javascript, and my serverside coding in VBS. No special reason for
the latter.
I try to avoid client side scripting altogether, but when I can't, I use
JavaScript, too. VBS is pretty useless on a public web page when so many
people are using Firefox or some other non-IE browser. My public server
is Linux hosted Apache, so I use PHP for server side scripting.
--
Crash

Registered pedophobe
Mayayana
2014-09-28 01:31:28 UTC
Permalink
I like to give things IDs and classes. A sample of typical
usage is here. (See the MSI editor):

http://www.jsware.net/jsware/msicode.php5
--
-
"Dave "Crash" Dummy" <***@invalid.invalid> wrote in message news:m06giv$ca0$***@dont-email.me...
| The code below is a simplified version of code I use to edit cell
| content in a table. It works fine. I can change style, text, whatever.
| What I would like to do is read the row and cell location. My fantasy
| code would read something like "r=obj.row.number" and "c=obj.cell.number."
| Is there such a thing in the real world?
|
| '---------------------------------- Demo.hta
| --------------------------------------------
| <HTA:APPLICATION ID="oHTA" APPLICATIONNAME="Demo" WindowState="maximize">
| <html><body>
| <TABLE id="tbl" border=1>
| <TR><TD onClick="hilite(this)">Text</TD><TD
| onClick="hilite(this)">Text</TD></TR>
| <TR><TD onClick="hilite(this)">Text</TD><TD
| onClick="hilite(this)">Text</TD></TR>
| </TABLE>
| </body>
| <script type="text/vbs">
| sub hilite(obj)
| if obj.style.fontWeight="bold" then
| obj.style.fontWeight="normal"
| else
| obj.style.fontWeight="bold"
| end if
| end sub
| </script>
| </html>
|
|
| --
| Crash
|
| "The fewer the facts, the stronger the opinion."
| ~ Arnold H. Glasow ~
Dave "Crash" Dummy
2014-09-28 12:23:25 UTC
Permalink
I like to give things IDs and classes. A sample of typical usage is
http://www.jsware.net/jsware/msicode.php5
I also like giving key elements IDs, like "tbl" in my demo script. I
just wondered if there was a generic way to retrieve row and cell
information, which Evertjan kindly provided. There are 210 active
cells in my application, and providing unique IDs for them would be
tedious.

Referring to your code, it seems like it would be simpler to replace
this:
RowDex = GetRowIndex(window.event.srcElement.parentElement.id)
ColDex = GetColIndex(window.event.srcElement.id)
with this:
RowDex=window.event.srcElement.parentNode.rowIndex
ColDex=window.event.srcElement.cellIndex
and eliminate the GetRowIndex and GetColIndex functions.
--
Crash

Give a man a fish, and he eats for a day.
Teach a man to fish, and his wife hates you for a lifetime.
Mayayana
2014-09-28 16:26:07 UTC
Permalink
| Referring to your code, it seems like it would be simpler to replace
| this:
| RowDex = GetRowIndex(window.event.srcElement.parentElement.id)
| ColDex = GetColIndex(window.event.srcElement.id)
| with this:
| RowDex=window.event.srcElement.parentNode.rowIndex
| ColDex=window.event.srcElement.cellIndex
| and eliminate the GetRowIndex and GetColIndex functions.

That does look like it would work. Maybe I should update
the DOM I reference to include post-IE4 elements. :)

On the other hand, I'm not sure I'll change my methods.
I like having IDs and classes for things.
Dave "Crash" Dummy
2014-09-28 17:42:19 UTC
Permalink
Post by Mayayana
| Referring to your code, it seems like it would be simpler to replace
| RowDex = GetRowIndex(window.event.srcElement.parentElement.id)
| ColDex = GetColIndex(window.event.srcElement.id)
| RowDex=window.event.srcElement.parentNode.rowIndex
| ColDex=window.event.srcElement.cellIndex
| and eliminate the GetRowIndex and GetColIndex functions.
That does look like it would work. Maybe I should update
the DOM I reference to include post-IE4 elements. :)
On the other hand, I'm not sure I'll change my methods.
I like having IDs and classes for things.
Whatever works. I use classes and IDs too, just not in this instance.
--
Crash

"In politics, stupidity is not a handicap."
~ Napoleon Bonaparte ~
Loading...