How can I call a vbscript function from html?

自作多情 提交于 2019-12-11 14:13:59

问题


This is what I have so far. I'm trying to use IE for user input. All I need help with is the 'OnClick' thing that is supposed to be calling myfunc().

'global variables
Dim objIE, screen, w, h


GetClient



'==============================================SUBS AND FUNCTIONS BELOW=================================================
Sub GetClient

Set objIE = CreateObject("InternetExplorer.Application")
set screen = ObjIE.Parent
w = screen.width
h = screen.height

'make IE look like an input box kinda
objIE.Navigate("about:blank")
objIE.Document.Body.Style.overflow = "auto"
objIE.document.title        = "--------------------BITB Client--------------------"
objIE.visible       = true
objIE.MenuBar       = False
objIE.ToolBar       = False
objIE.AddressBar    = false
objIE.Resizable     = False
objIE.Width         = 400
objIE.Height        = 280
objIE.Left          = (w/2) - 200
objIE.Top           = (h/2)

'html form to get input
objIE.Document.Body.InnerHTML = "<p>-Please choose a client listed below-</p>" _
    & "<form>" _
    & "<input type=""radio"" name=""client"" value=""176"">176<br>" _
    & "<input type=""radio"" name=""client"" value=""515"">515<br>" _
    & "<input type=""radio"" name=""client"" value=""760"">760<br>" _
    & "<input type=""submit"" value=""submit"" OnClick=""VBScript:myfunc()"">" _
    & "</form>"


end sub

function myfunc() 
msgbox "yay it works"
end function

I've looked everywhere and I don't understand why this doesn't work. If anyone could help it would be greatly appreciated. =]. Also if anyone feels like making the function that could tell which radio button was selected go right ahead.


回答1:


Change your code to something like this:

'global variables
Dim objIE, screen, w, h

GetClient
Do While objIE.document.All.OK.Value = 0
  WScript.Sleep 200
Loop
myfunc
objIE.Quit

'==========================SUBS AND FUNCTIONS BELOW==========================
Sub GetClient
  Set objIE = CreateObject("InternetExplorer.Application")
  ...
  objIE.Top           = (h/2)

  'html form to get input
  objIE.Document.Body.InnerHTML = "<p>-Please choose a client listed below-</p>" _
    & "<!--form--&gt" _
    & "<input type=""radio"" name=""client"" value=""176"">176<br&g;" _
    & "<input type=""radio"" name=""client"" value=""515"">515<br>" _
    & "<input type=""radio"" name=""client"" value=""760"">760<br>" _
    & "<input type='hidden' id='OK' value='0'>" _
    & "<input type=""submit"" value=""submit"" OnClick=""VBScript:OK.Value=1"">" _
    & "<!--/form-->"
end sub

function myfunc()
  msgbox "yay it works"
end function


来源:https://stackoverflow.com/questions/19532120/how-can-i-call-a-vbscript-function-from-html

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!