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 Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

attaching a custom event to a tabl cell

Status
Not open for further replies.

MuadDubby

Programmer
Sep 23, 1999
236
CA
Anyone know how I can create a custom event and then attach it to a table cell (TD)?

I'm pretty sure I have to use the public:event code for this, but I'm kind of stumped.

Here's the code I have so far:

Code:
<html>
<head>
<public:event id=myEvent name=onmyevent />
</head>
<body>
<table width="215" border="1" cellspacing="7" cellpadding="0">
   <tr height="48">
     <td>
       &nbsp;&nbsp;&nbsp; Maintenance Menu
     </td>
   </tr>
   <tr height="26.5">
     <td class="TDRegularImage" onclick=alert("hello1")>
       &nbsp;&nbsp;&nbsp;&nbsp;<b>P.O. Table </b>
     </td>
   </tr>
</table>
</body>
</html>

This displays a simple table, and clicking on cell #2 displays a message. I want to be able to display the message by reacting to 'onmyevent' instead of 'onclick'. Any ideas?

Don't worry about how the event will get fired; I'm actually embedding the browser control in a VB form and firing the event from the form itself.

Thx in advance,
.DaviD.
 

If you're firing the event yourself, then surely all you would need to do would be:

Code:
<td class="TDRegularImage" onmyevent="alert('hello');">

Hope this helps,
Dan
 
Hi Billy

Tried that. Unfortunately, the custom event apparently has to be declared somewhere. When I tried to do something like that, I got an error saying that the object did not exist.

Here's what I am doing in VB (I hope your familiar with it). Create yourself a form and put a browser and and a button it. Then save the above HTML code into C:\temp\temp.html.

Code:
Private Sub Form_Load()
    WebBrowser1.Navigate2 "C:\temp\temp.html"
End Sub

Private Sub Command1_Click()
    Dim doc As HTMLDocument
    Set doc = WebBrowser1.Document

    ' the following works, because I'm firing the onclick
    ' event on the second cell
    doc.body.children.Item(0).cells.Item(1).FireEvent ("onclick")
    ' the following does not work, and I get an error
    ' saying that the argumant supplied ("onmyevent") 
    ' is invalid.
    doc.body.children.Item(0).cells.Item(1).FireEvent ("onmyevent")
    
End Sub

.DaviD.
 
I think the public:event syntax you show is for HTCs (HTML Components) only. See here for more info:


So it's possible that you cannot create your own events on the fly without using HTCs... Which kind of restricts which browsers this would work in, too.

Dan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top