2013-10-23 126 views
0

這是我到目前爲止。我正在嘗試使用IE瀏覽器進行用戶輸入。我需要幫助的是'OnClick',應該叫myfunc()。如何從html調用vbscript函數?

'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 

我到處尋找,我不明白爲什麼這不起作用。如果有人可以幫助它,將不勝感激。 =]。此外,如果任何人覺得可以告訴哪個單選按鈕被選中,可以直接進入該功能。

回答

0

更改您的代碼是這樣的:

'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-->" _ 
    & "<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