Re: array to html select
- From: mr_unreliable <kindlyReplyToNewsgroup@xxxxxxxxxxx>
- Date: Tue, 22 Nov 2005 13:08:05 -0500
hi RSchneid,
Here is an old script which may do what you are looking for.
cheers, jw ____________________________________________________________
You got questions? WE GOT ANSWERS!!! ..(but, no guarantee the answers will be applicable to the questions)
rschneid76@xxxxxxxxx wrote:
Hi,
I would like to query a db for all apps and then pass that list to a drop down box in IE. I have sql query working correctly building the array of applications. However, I am not sure how i can pass the array and then create the drop down box to be displayed. Below is the code any help would be appreciated. thanks!!
vbs script that queries db gets results and then should pass to IE form ************************************* redim arrApps(0) Title = "Username and Office Input" Text2 = "You entered:" + vbCRLF path = WScript.ScriptFullName path = Left(path, InstrRev(path, "\"))
** sql query *********
sServer = "SQLSERVER" sLogin = "ACCOUNT" sPwd = "PASSWORD" sDB = "DATABASE"
Set oCn = CreateObject( "ADODB.Connection" ) Set oRs = CreateObject( "ADODB.Recordset" ) Set oFso = CreateObject("Scripting.FileSystemObject")
oCn.ConnectionString = "PROVIDER=SQLOLEDB" & _ ";SERVER=" & sServer & _ ";UID=" & sLogin & _ ";PWD=" & sPwd & _ ";DATABASE=" & sDB & ""
oCn.open oRs.Open "Select Distinct(app) as result from APP_TABLE order by product ASC", oCn
if oRs.EOF then
else While Not oRs.EOF
strAPP = oRs.Fields("result").Value Call AddStringToArray(arrApps, strAPP, -1) oRs.MoveNext
Wend end if
oCn.close
' *** launch Internet Explorer *** Set oIE = WScript.CreateObject("InternetExplorer.Application") oIE.left=0 ' window position oIE.top = 0 ' and other properties oIE.height = 750 oIE.width = 1000 oIE.menubar = 0 ' no menu oIE.toolbar = 0 oIE.statusbar = 0 ' commented out, because it causes a corrupted window ' oIE.resizable = 0 ' disable resizing oIE.navigate path + "Form1.htm" ' Form oIE.visible = 1 ' keep visible
' Important: wait till MSIE is ready Do While (oIE.Busy)
Loop
' Wait till the user clicks the OK button ' Use the CheckVal function ' Attention: Thanks to a note from M. Harris, we can make the ' script a bit more fool proof. We need to catch the case that ' the user closes the form without clicking the OK button. On Error Resume Next Do ' Wait till OK button is clicked
Loop While (oIE.document.script.CheckVal()=0)
arrApps = ""&oIE.Document.ValidForm.fRegion.Value
html form file *************************************************************************
<html>
<head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <meta name="GENERATOR" content="Microsoft FrontPage 5.0"> <title>User Information</title> </head>
<body bgcolor="#003366"> <script language="VBScript"> <!--
Dim ready Public TheForm
Sub Button1_OnClick ' If the user clicks the OK button, we must flag this to ' the polling WSH script ready = 1 ' User input is ready End Sub
Sub window_onload() ' Here we may initialize the form Set TheForm = Document.ValidForm TheForm.fRegion.Value="" ready = 0 ' User input not ready
for each app in arrApps <option value = fRegion >fRegion</option> next
End Sub
Public Function CheckVal () ' This is called from the host to check whether ' the user has clicked the OK-button CheckVal = ready End function
'--> </script>
' script by: Tom Lavedas
' posted on: microsoft.public.scripting.vbscript
' dated: Monday, February 03, 2003 1:23 PM
'
Option Explicit
Dim aOpt(7)
aOpt(0) = "\\mail\HP 4100 - Clinical - Clare"
aOpt(1) = "\\mail\HP 4000 - Admissions"
aOpt(2) = "\\medical\HP LaserJet 4000 - Medical"
aOpt(3) = "\\mail\HP 4000 - Front Desk"
aOpt(4) = "\\mail\HP 4000 - Business Office"
aOpt(5) = "\\mail\HP 4100 - Clinical - HRC"
aOpt(6) = "\\mail\HP 4100 - Business Office"
aOpt(7) = "\\victoria\HP 4500"
wsh.echo "You selected:", SelectBox("Select a default printer", aOpt)
Function SelectBox(sTitle, aOptions)
Dim oIE, s, item
set oIE = CreateObject("InternetExplorer.Application")
With oIE
.ToolBar = False : .RegisterAsDropTarget = False
.StatusBar = False : .Navigate("about:blank")
While .Busy : WScript.Sleep 100 : Wend
With .document
With .ParentWindow
if Instr(.navigator.appVersion, "MSIE 6") = 0 Then
oIE.FullScreen = True
End if
.resizeto 400,150
.moveto .screen.width/2-200, .screen.height/2-50
End With ' ParentWindow
s = "<html><head><title>" & sTitle & " " & String(80, ".") & "</title></head>" _
& "<script language=vbs>bWait=true</script>" _
& "<body bgColor=Silver><center><b>" & sTitle & "<b><p>" _
& "<select id=entries size=1 style='width:250px'>" _
& " <option selected>" & sTitle & "</option>"
For each item in aOptions
s = s & " <option>" & item & "</option>"
Next
s = s & " </select><p>" _
& "<button id=but0 onclick='bWait=false'>OK</button>" _
& "</center></body></html>"
.WriteLn(s)
With .body
.scroll="no"
.style.borderStyle = "outset"
.style.borderWidth = "3px"
End With ' Body
.all.entries.focus
oIE.Visible = True
On Error Resume Next
While .ParentWindow.bWait
WScript.Sleep 100
if oIE.Visible Then SelectBox = "Aborted"
if Err Then Exit Function
Wend ' Wait
On Error Goto 0
With .ParentWindow.entries
SelectBox = .options(.selectedIndex).text
End With
End With ' document
.Visible = False
End With ' IE
End Function
- References:
- array to html select
- From: rschneid76
- array to html select
- Prev by Date: Open IE using VBScript
- Next by Date: Re: Login Script refuses to map a share?
- Previous by thread: array to html select
- Next by thread: Fire off a subroutine when a new item selected in a select
- Index(es):