Click to See Complete Forum and Search --> : Using variable contents in DOM references


TBor
05-27-2003, 12:48 PM
Howdy all. This is a "kinda ASP / kinda VBScript" question, but hopefully someone here can help me out. I've done this before, but just plain forget how.

I've got an ASP page that's reading values from a DB and displaying them in a table. Each row of the table has its own id (the primary key from the DB). There are 4 columns in my table, and each of the <td> tags gets a unique name/id based on the row ID (the id/names are "desc8", targ8" etc. for the <td> tags in row 8, for example).

What I want to do is, on single event in a row, read the innerText of all <td> tags in that row (i.e. click on a button in row 8, retrieve all the innerText from the table cells in row 8). The event passes the row ID to my client-side subroutine, and I create variables with the respective <td> id/names. (i.e. descID = "desc" + rowID"

Now, the big question: how do I get the innerText using the variable contents, not the variable name?

For example: document.form.desc8.innerHTML will get me the text I want from row 8. However, if the string "desc8" is stored in variable descID, I'm stuck. I thought it was something like document.form.item(descID).innerText, or document.form.value(descID).innerText, but those don't seem to work.

Any help would be greatly appreciated.

Thanks,
TBor

Here's what my code (partially) looks like:

sub Click(rowID)
descID = "desc" & rowID
targID = "targ" & rowID
...
descText = document.form.?????.innerText
targText = document.form.?????.innerText
end sub

TBor
05-28-2003, 09:36 AM
Thanks Dave!

Unfortunately, no dice - your suggestion doesn't do anything for me. However, I DID manage to get things working the way I wanted, but using document.all.item(descid).innerText.

Not really sure why things won't work they way you suggested. I appreciate the help though, and if you have any ideas as to why my solution works and yours doesn't seem to, I'd love to hear them. I'm as confused as I've ever been, but slightly relieved because things seem to be working, even though I don't really understand why.

Thanks again!
TBor

TBor
05-29-2003, 09:08 AM
Thanks again Dave.

However, still no dice, but I think I know why - if I'm right in assuming this, that is.

The elements I'm trying to read the innerText from are SPAN tags (I had tried earlier to read from TD tags, but that didn't work for some reason). My assumption is that, because they're not really FORM elements that they wouldn't show up in the document.form collection, but they will show up in the document.all collection.

I'm making this assumption because I've got 2 tables within my FORM (one has the form INPUT tags, the other has the data from the DB that I'm trying to read).In Visual InterDev (my dev environment), there's a way to view then HTML hierarchy for a page, and for this page it shows the table with the INPUT tags as being within the form, but the other table is shown outside the form.

All the tags I'm playing with have id and name attributes (set the same as one another). Oh, and I've got FORM tags, with a unique form name & ID even! :-)

But, not that big of a deal anymore now that I have things working for me. Now it's more just a curiosity. Thanks for the help!

TBor