Forum rules Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 15 years and 1 week old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
VBScript:
Set objRow = objTableBody.InsertRow()
objRow.Style.fontWeight = "bold"
Set objCell = objRow.InsertCell()
objCell.InnerText = "Name"
Set objCell = objRow.InsertCell()
objCell.InnerText = "Salary"
Set objRow = objTableBody.InsertRow()
Set objCell = objRow.InsertCell()
objCell.InnerText = "Frank"
Set objCell = objRow.InsertCell()
objCell.InnerText = "$52,362.54"
HTML:
<TABLE ID = "objTable" border = "1" >
<TBODY ID = "objTableBody">
</TBODY>
</TABLE>
The above works all fine and dandy, but when you start adding attributes to the DOM method, like an image, then I start having issues. Specifically the "onclick" attribute. I have tried numerous ways to get it to work and it's not playing nice. Does anyone have a way in invoke this utilizing VBScript?
Set img = document.createElement("img")
img.src="file:////server/share/picture.bmp"
img.alt = "I want to double-click this image and run something"
img.setAttribute "onClick", "vbScript:Test()" 'doesn't work
img.setAttribute "onClick", "Test()" 'doesn't work
img.setAttribute "onClick", Test 'doesn't work
img.onClick "vbScript:Test()" 'doesn't work
img.onClick "Test()" 'doesn't work
img.onClick "Test" 'doesn't work
img.onClick Test() 'doesn't work
img.style.width="25"
img.style.height="25"
objcell.appendChild(img)
You are tryiong to use an "attribute" to set an "event". TIy need to use the event system to define this. This requires a wireup of teh function to the event. The is done with teh "attachEvent" methgod of teh object.
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>My HTML Application</title>
<script language="vbscript">
Sub window_onload()
Set img = document.createElement("img")
img.src="http://tbn3.google.com/images?q=tbn:59BjliqWWqr1eM:http://teacupyorkies.files.wordpress"
img.alt = "I want to double-click this image and run something"
set fptest = getRef("test")
img.attachEvent "onclick", fptest
bdy.appendChild( img)
End Sub
Sub Test()
MsgBox "clicked"
End Sub
</script>
<hta:application
applicationname="MyHTA"
border="dialog"
borderstyle="normal"
caption="My HTML Application"
contextmenu="no"
icon="myicon.ico"
maximizebutton="no"
minimizebutton="yes"
navigable="no"
scroll="no"
selection="no"
showintaskbar="yes"
singleinstance="yes"
sysmenu="yes"
version="1.0"
windowstate="normal"
>
</head>
<body >
<div id="bdy"></div>
<!-- HTML goes here -->
</body>
</html>
Shorthand for this: set fptest = getRef("test") img.attachEvent "onclick", fptest is this: img.attachEvent "onclick", getRef("test") <object>.detachAEvent "onclick"
will remove teh event.
The function pointer can point to either a "Sub" or a "function" but function must take no arguments.
One other note:
The events "onattachevent" and "ondetachevent" are fired.
But see, that's the thing about being able to find something on the web, you have to know what to search for. I searched atleast 20 times with .createElement("img") + VBS + VBscript and only found a plethora of articles on JScript, which I don't use very often. I was about to start developing again in ASP.NET, so I know who to shoot ? to...
Here - on a system with NET 3.5 and Silverlight installed. Copy and paste this into a file and give it an XAML extension then double click the file. Be sure it has the correct extrension an and no TXT after it.
This will demo how powerful teh next generration of page language is and can be. It will be able to be used to build forms in PowerShell V2 (requires delegates/events). It is much easier to work with than DHTML and can create both dektop WinForms and Web pages. Scripts will be written using a "code-behind" page in the language of your choice.
Consider this an HTA on steroids. The next versions of this technology is ready for release shortly. It promises to be more flexible and powerful than any page languge preceeding it.
The concept will, most likely, drive a number of other vendors to create similar page languages that may become industry specific. The idea of moving to an XML descripbed object model for both the creation of teh object and teh sorage and editing of that object is not new. PowerShell already does this with it's object format to CLIXML.
Many service architecture have been saving objects using this method. Now we will have it fo r Windows/Web Forms.
I have already played with Silverlight in an HTA, the "Scripting Guys" had an article on it. I haven't really delved into PowerShell yet because I really like the GUI interface that HTA's provide and I can do most things in VBScript. In PS, are you utilizing InternetExplorer.Application and just writing to it dynamically? HTA's just give you the ablility to subvert all of the ActiveX security which is obviously convenient for client-side scripting.
This topic is 15 years and 1 week old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.