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

VBScript generated HTML<script> sent to IE ???

Status
Not open for further replies.

DANZIG

Technical User
Mar 8, 2001
142
US
Hello All,
I haven't used the HTML aspect of WSH/VBS up to this point in my scripting so I'm a little confused on how to accomplish what I'm trying to develope.
I Have the need to use a WHS/VBS script to send HTMl/<script> srteams to IE in order to allow the script to use a ( script generated ) HTML interface for user Input / output.

Below is what I've got so far, the problem I'm having is with the button <tag>.
If you view the source from the script generated html page and paste it in to a static html page it works as it should, but in the generated verison the button does not work.

What have I done or not done correctly?
Any help would be appreciated.

(code will cut and paste in working fashion from this webpage )
_____________________________________________________________________________________________________
Start Script
_____________________________________________________________________________________________________

Set MSIE = CreateObject(&quot;InternetExplorer.Application&quot;)
On Error Resume Next


'
'Setup IE for Display Box.
'


SetupMSIE

MSIE.Document.Write &quot;<HTML><TITLE>HTML / VBS Testing</TITLE><BODY bgcolor=#ffffff><FONT FACE=ARIAL>&quot;
MSIE.Document.Write &quot;<B>Please Make A Selection</B><BR>&quot;


'
'***Select Elements***
'


C_1 = &quot;Choice 1&quot;
C_2 = &quot;Choice 2&quot;
C_3 = &quot;Choice 3&quot;
C_4 = &quot;Choice 4&quot;
C_5 = &quot;Choice 5&quot;
C_6 = &quot;Choice 6&quot;
C_7 = &quot;Choice 7&quot;


'
'***Select Input Box***
'


MSIE.Document.Write &quot;<select>&quot;
MSIE.Document.Write &quot;<option selected>&quot;&C_1&&quot;</option>&quot;
MSIE.Document.Write &quot;<option>&quot;&C_2&&quot;</option>&quot;
MSIE.Document.Write &quot;<option>&quot;&C_3&&quot;</option>&quot;
MSIE.Document.Write &quot;<option>&quot;&C_4&&quot;</option>&quot;
MSIE.Document.Write &quot;<option>&quot;&C_5&&quot;</option>&quot;
MSIE.Document.Write &quot;<option>&quot;&C_6&&quot;</option>&quot;
MSIE.Document.Write &quot;<option>&quot;&C_7&&quot;</option>&quot;
MSIE.Document.Write &quot;</select>&quot;


'
'***Select Button***
'


MSIE.Document.Write &quot;<INPUT TYPE=&quot;&chr (34)&&quot;Button&quot;&chr (34)&&quot; NAME=&quot;&chr (34)&&quot;Button1&quot;&chr (34)&&quot; VALUE=&quot;&chr (34)&&quot;Select&quot;&chr (34)&&quot;><SCRIPT FOR=&quot;&chr (34)&&quot;Button1&quot;&chr (34)&&quot; EVENT=&quot;&chr (34)&&quot;onClick&quot;&chr (34)&&quot; LANGUAGE=&quot;&chr (34)&&quot;VBScript&quot;&chr (34)&&quot;>MsgBox &quot;&chr (34)&&quot;Button Pressed!&quot;&chr (34)&&quot;</SCRIPT>&quot;

MSIE.Document.Write &quot;<HR>&quot;
MSIE.Document.Write &quot;<BR>Thank You!&quot;
MSIE.Document.Write &quot;</Body></HTML>&quot;


'
'***Show The Exact HTML CODE BEING SENT TO IE***
'


Wscript.Echo &quot;<INPUT TYPE=&quot;&chr (34)&&quot;Button&quot;&chr (34)&&quot; NAME=&quot;&chr (34)&&quot;Button1&quot;&chr (34)&&quot; VALUE=&quot;&chr (34)&&quot;Click&quot;&chr (34)&&quot;><SCRIPT FOR=&quot;&chr (34)&&quot;Button1&quot;&chr (34)&&quot; EVENT=&quot;&chr (34)&&quot;onClick&quot;&chr (34)&&quot; LANGUAGE=&quot;&chr (34)&&quot;VBScript&quot;&chr (34)&&quot;>MsgBox &quot;&chr (34)&&quot;Button Pressed!&quot;&chr (34)&&quot;</SCRIPT>&quot;


'
'*** Setup Internet Explorer ***
'


Sub SetupMSIE
MSIE.Navigate &quot;About:Blank&quot;
MSIE.ToolBar = False
MSIE.StatusBar = False
MSIE.Resizable = False

Do
Loop While MSIE.Busy

SWidth = MSIE.Document.ParentWindow.Screen.AvailWidth
SHeight = MSIE.Document.ParentWindow.Screen.AvailHeight
MSIE.Width = SWidth * .3
MSIE.Height = SHeight * .3
MSIE.Left = (SWidth - MSIE.Width)/2
MSIE.Top = (SHeight - MSIE.Height)/2

MSIE.Visible = True
End Sub
 
When you want to add an event handler to a generated tag, you can't do it the way you done. You've got to use the &quot;getRef&quot; method. I used it many times in DHTML but not really in the way you do. I think that sould be used this way :
Code:
'*** First, define button :
MSIE.Document.Write &quot;<INPUT TYPE=&quot;& chr(34)& &quot;Button&quot; & chr(34) & &quot; NAME=&quot; & chr(34) & &quot; ID=&quot; & chr(34) & &quot;Button1&quot; & chr(34) & &quot; VALUE=&quot; & chr(34) & &quot;Select&quot; & chr(34)& &quot;/>&quot;

'*** Second, define Function to be called :
MSIE.Document.Write &quot;<SCRIPT LANGUAGE=&quot; & chr(34) & &quot;VBScript&quot; & chr(34) &&quot;>
MSIE.Document.Write &quot;Function testButton() & chr(13) & MsgBox &quot; & chr(34) & &quot;Button Pressed!&quot; & chr(34)
MSIE.Document.Write &quot;End Function&quot;
MSIE.Document.Write &quot;</SCRIPT>&quot;

'*** Third, Associate Function to button event :
Dim ButtonTag ' Beware : don't confuse with german &quot;Gutten Tag&quot;
LOL
Code:
Set ButtonTag = MSIE.Document.getElementById(&quot;Button1&quot;)
ButtonTag.onclick = getRef(&quot;testButton&quot;)

NOTES :
1) Be carefull, I may forgot some quotes or other in the above code.
2) This function (getRef) works correctly in DHTML but I'm not sure that it'll find the reference to the function when not in the same HTML page. If that does'nt work this way, you can make it work by adding a script to your page in head that'll do the same thing :

Code to add between Head Tags :
Code:
Dim ButtonTag
Set ButtonTag = Document.getElementById(&quot;Button1&quot;)
ButtonTag.onclick = getRef(&quot;testButton&quot;)

Hope this will work or help !!!
Water is not bad as long as it stays out human body ;-)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top