Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


Big bad DOM

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,36435
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Big bad DOM
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 Big bad DOM - 7/23/2006 10:05:45 PM   
  Sybre

 

Posts: 27
Score: 0
Joined: 7/19/2006
Status: offline
OK, this one's about using tables with the DOM...

I'm dynamically generating a table in my hta and I want to have the line which has been clicked highlight.
I can set the onClick for each row to call a function which does the highlighting but the problem is, I don't know how to identify which row called it.

eg
oRow.onClick = HighlightRow(Row Number)

in HighlightRow:
document.getelementbyid(sTable).rows(Row Number).style.backgroundcolor = "yellow"

I thought about having IDs for each row but the table needs to remain dynamic as the user will be adding and removing rows.
Any thoughts?
 
 
Post #: 1
 
 RE: Big bad DOM - 7/24/2006 12:56:29 AM   
  ehvbs

 

Posts: 2169
Score: 50
Joined: 6/22/2005
From: Germany
Status: offline
Hi Sybre,

you can use "Me" to pass the current DOM TD element to a suitable event
handler sub. Something along the lines of:


      

Good luck!

(in reply to Sybre)
 
 
Post #: 2
 
 RE: Big bad DOM - 7/24/2006 1:30:24 AM   
  Sybre

 

Posts: 27
Score: 0
Joined: 7/19/2006
Status: offline
Brilliant - I had a feeling there should be something like that but couldn't for the life of me figure out what it was. 
Thanks.

(in reply to ehvbs)
 
 
Post #: 3
 
 RE: Big bad DOM - 8/3/2006 2:42:36 AM   
  Sybre

 

Posts: 27
Score: 0
Joined: 7/19/2006
Status: offline
Hmm, on further investigation it appears I can't seem to set the onclick for the row the way I want to....

Setting the onclick for the row/cell using HTML tags is fine but I'd really like generate the table without having to set the innerhtml of the div using sHTML = sHTML & "<TD onclick=""onTDClick( Me )"">"
I've been adding my rows/cells dynamically using something like this:

Set oRow = document.createElement("TR")
oTBody.appendChild(oRow)
set oCell = document.createElement("TD")
oRow.appendChild(oCell)

I thought I should be able to set the onclick properties before using appendChild by:
oCell.onClick = mySubroutine(sMyArgument)

or later by:
myCellID.onclick = mySubroutine(sMyArgument)

Neither of these work - can anyone tell me why and how I can do this?

(in reply to Sybre)
 
 
Post #: 4
 
 RE: Big bad DOM - 8/3/2006 3:34:43 AM   
  ehvbs

 

Posts: 2169
Score: 50
Joined: 6/22/2005
From: Germany
Status: offline
Hi Sybre,

I don't think that this is possible. To set the onclick attribute you may use

    oCell.setAttribute "onclick", GetRef( "onTDClick2" )

or

    oCell.onclick = GetRef( "onTDClick2" )

where onTDClick2() is a Sub with no parameters. But I see no way to insert
the Me parameter when using this method.

Sorry about that!

ehvbs

(in reply to Sybre)
 
 
Post #: 5
 
 RE: Big bad DOM - 8/3/2006 3:37:42 AM   
  Sybre

 

Posts: 27
Score: 0
Joined: 7/19/2006
Status: offline
Oh well, thanks anyway!

(in reply to ehvbs)
 
 
Post #: 6
 
 RE: Big bad DOM - 8/3/2006 4:23:04 AM   
  ehvbs

 

Posts: 2169
Score: 50
Joined: 6/22/2005
From: Germany
Status: offline
Hi Sybre,

you may use DOM to create your table and pass Me (== this) to a 'one-for-all handler' -
but you'll have to use JScript:


      

Good luck!

(in reply to Sybre)
 
 
Post #: 7
 
 RE: Big bad DOM - 8/16/2006 12:40:39 AM   
  Sybre

 

Posts: 27
Score: 0
Joined: 7/19/2006
Status: offline
Aha - I've found a way to do it with vbscript....!
Although you can't pass parameters with getref, you can find out what triggered it using the event object (window.event).

The onclick event is assigned when the row is generated by:
  
   oRow.onclick = getref("RowClicked")

Then the element which caused the event can bereferenced in RowClicked using:
  
   window.event.srcElement

However....
This by itself actually references the cell not the row - so I stuck in an extra bit to work my way up to the row:

        Dim oThisElement
        Set oThisElement = window.event.srcElement
        Do Until oThisElement.tagName = "TR"
            Set oThisElement = oThisElement.parentElement
        Loop

I did it as a loop not just a single step up because some of my cells contain elements so if they are clicked on then I'd have to go up two levels etc.

(in reply to ehvbs)
 
 
Post #: 8
 
 RE: Big bad DOM - 8/16/2006 1:04:41 AM   
  ehvbs

 

Posts: 2169
Score: 50
Joined: 6/22/2005
From: Germany
Status: offline
Hi Sybre,

because you found a VBScript way (congratulations!) where I saw only JScript,
I 'updated' my script using your ideas.


      

Thanks for you persistency!

ehvbs

(in reply to Sybre)
 
 
Post #: 9
 
 RE: Big bad DOM - 8/16/2006 1:10:59 AM   
  Sybre

 

Posts: 27
Score: 0
Joined: 7/19/2006
Status: offline
I did appreciate your JScript answer (put me on the right track for finding the vbscript way) - just was limited to using vbscript only (my boss's requirement)

(in reply to ehvbs)
 
 
Post #: 10
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Big bad DOM Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts