我有一个简单的表格
<div id="stylized" class="myform">
<form id="mysmartform">
<h1>CourtSmart Server Status</h1>
<p>Are the servers running?</p>
<label>Yes
<span class="small">All Servers Are Running</span>
</label>
<input type="radio" name="formradio" id="stylized" value="yes" />
<label>No
<span class="small">We Have A Problem</span>
</label>
<input type="radio" name="formradio" id="stylized" value="no" />
<label>eMail
<span class="small"></span>
</label>
<select name="formemail" size="1">
<option value="someone@example.com" selected="selected">someone@example.com</option>
<option value="someone@example.com">someone@example.com</option>
<option value="someone@example.com">someone@example.com</option>
<option value="someone@example.com">someone@example.com</option>
<option value="someone@example.com">someone@example.com</option>
</select>
<button type="submit" id="sendReport">Send Status Report</button>
<div class="spacer"></div>
使用VBScript我想访问所选单选按钮和所选电子邮件地址的值,只需执行一个简单的MsgBox即可显示它
答案 0 :(得分:1)
Option Explicit
Dim objIE : Set objIE = CreateObject("InternetExplorer.Application")
objIE.Visible = False
objIE.Navigate "file://C:/form.html"
Do Until objIE.ReadyState = 4
WScript.Sleep 100
Loop
Dim value_running
Dim value_problem
Dim result
value_running = objIE.Document.getElementsByTagName("input").item(0).value
value_problem = objIE.Document.getElementsByTagName("input").item(1).value
If StrComp(value_running,"yes")=0 Then
result = 0
ElseIf StrComp(value_problem,"yes")=0 Then
result = 1
Else
result = -1
End If
Wscript.Echo Result
答案 1 :(得分:0)
如果你的意思是运行一个vbscript,在IE中添加一些GUI并获取值,这是一个例子
Set web = CreateObject("InternetExplorer.Application")
If web Is Nothing Then
msgbox("Error while loading Internet Explorer")
Wscript.Quit
Else
with web
.Width = 300
.Height = 175
.Offline = True
.AddressBar = False
.MenuBar = False
.StatusBar = False
.Silent = True
.ToolBar = False
.Navigate "about:blank"
.Visible = True
end with
End If
'Wait for the browser to navigate to nowhere
Do While web.Busy
Wscript.Sleep 100
Loop
'Wait for a good reference to the browser document
Set doc = Nothing
Do Until Not doc Is Nothing
Wscript.Sleep 100
Set doc = web.Document
Loop
'Write the HTML form
doc.Write "Give me a name<br><form><input type=text name=name ><input type=button name=submit id=submit value='OK' onclick='javascript:submit.value=""Done""'></form>"
Set oDoc = web.Document
Do Until oDoc.Forms(0).elements("submit").Value <> "OK"
Wscript.Sleep 100
If web Is Nothing or Err.Number <> 0 Then
msgbox "Window closed"
Wscript.Quit
End If
Loop
name = oDoc.Forms(0).elements("name").value
oDoc.close
set oDoc = nothing
web.quit
set web = nothing
Wscript.echo "Hello " & name