Roland
Mon Dec 29 05:16:56 CST 2003
"mishkare" wrote:
> I am pretty new to VBscripting so please bare with me.
> I am using a client-side VBScript that displays its info in a IE window,
and
> accepts input via a checkbox form.
> I have tried to include Roland's example, but I still just don't have clue
> what I am doing.
>
> Here's a little snip to give you an idea of what I am trying to do.
This will work but if you want to submit the form, then you need an action.
Since you are using a 'continue' button to submit, then you need to put the
action and submit in the script.
Here is the code to work as my previous example: (I'm not sure what you're
doing with the ch() array. I don't see any values in it.)
Set objExplorer = CreateObject("InternetExplorer.Application")
objExplorer.Navigate "about:blank"
objExplorer.ToolBar = 0
objExplorer.StatusBar = 0
objExplorer.Width = 640
objExplorer.Height = 480
objExplorer.Left = 0
objExplorer.Top = 0
objExplorer.Visible = 1
Do While (objExplorer.Busy)
Wscript.Sleep 250
Loop
dim ch(8)
Set objDocument = objExplorer.Document
objDocument.Open
objDocument.Writeln "<html>"
objDocument.Writeln "<head><title>Web Laptop Updates</title>"
objDocument.Writeln "<script type=""text/vbscript"">"
objDocument.Writeln "sub button1_onClick()"
objDocument.Writeln "dim formCol, elCol, strMsg, lstrMsg"
objDocument.Writeln "set formCol = document.forms(""form1"")"
objDocument.Writeln "set elCol = formCol.tasks"
objDocument.Writeln "strMsg = ""You checked the following choice(s):"" &
vbCrLf"
objDocument.Writeln "lstrMsg = len(strMsg)"
objDocument.Writeln "for i = 0 to elCol.length-1"
objDocument.Writeln " if elCol(i).checked then"
objDocument.Writeln " strMsg = strMsg + elCol(i).value & vbCrLf"
objDocument.Writeln " end if"
objDocument.Writeln " next"
objDocument.Writeln " if len(strMsg) > lstrMsg then"
objDocument.Writeln " alert(strMsg)"
objDocument.Writeln " else"
objDocument.Writeln " alert(""You didn't make any choices."")"
objDocument.Writeln " end if"
objDocument.Writeln "end sub"
objDocument.Writeln "</script>"
objDocument.Writeln "</head>"
objDocument.Writeln "<body bgcolor='white'>"
objDocument.Writeln "<table>"
objDocument.Writeln "<tr><TD style=""width: 320px; height: 12px; font: bold
18pt sans"">Web Updates:</TD></tr>"
objDocument.Writeln "<tr><TD style=""width: 640px; text-align: center;
height: 12px""></td></tr>"
objDocument.Writeln "<tr><TD style=""width: 640px; height: 15px; text-align:
left"">"
objDocument.Writeln "<FORM NAME='Form1'>"
objDocument.Writeln "<span style=""font-weight: bold"">Check The box next to
the update to be installed:</span>"
objDocument.Writeln "<br /><INPUT TYPE=CHECKBOX NAME=""tasks""
value=""navu""" & ch(7) & " />Norton Anti-Virus Update"
objDocument.Writeln "<br /><INPUT TYPE=CHECKBOX NAME=""tasks""
value=""maps""" & ch(6) & " />Maps Update"
objDocument.Writeln "<br /><INPUT TYPE=CHECKBOX NAME=""tasks""
value=""subs""" & ch(4) & " />Substation Maps Update"
objDocument.Writeln "<br /><INPUT TYPE=CHECKBOX NAME=""tasks""
value=""comp""" & ch(5) & " />Comp Locations<br />"
objDocument.Writeln "<br /><input type=button name=""button1""
value=""Continue"" /><input type=reset name=""button2"" value=""Reset"" />"
objDocument.Writeln "</FORM></TD></TR></table></body></html>"
objDocument.Close
I changed the input names to tasks. They need to be the same. The values
will be passed.
To actually submit the form, I need an action and a call to submit. I'm not
sure what all is allowed for action and all examples I have seen call a
http:// document. I am assuming this is because you are now using IE so it
needs to be a file that IE supports.
Here is what I changed it to:
Set objExplorer = WScript.CreateObject("InternetExplorer.Application",
"IE_")
objExplorer.Navigate "about:blank"
objExplorer.ToolBar = 0
objExplorer.StatusBar = 0
objExplorer.Width = 640
objExplorer.Height = 480
objExplorer.Left = 0
objExplorer.Top = 0
objExplorer.Visible = 1
Do While (objExplorer.Busy)
Wscript.Sleep 250
Loop
Sub IE_onQuit()
Wscript.Quit
End Sub
dim ch(8)
Set objDocument = objExplorer.Document
objDocument.Open
objDocument.Writeln "<html>"
objDocument.Writeln "<head><title>Web Laptop Updates</title>"
objDocument.Writeln "<script type=""text/vbscript"">"
objDocument.Writeln "sub button1_onClick()"
objDocument.Writeln "dim formCol, elCol, strMsg, lstrMsg"
objDocument.Writeln "set formCol = document.forms(""form1"")"
objDocument.Writeln "set elCol = formCol.tasks"
objDocument.Writeln "strMsg = ""You checked the following choice(s):"" &
vbCrLf"
objDocument.Writeln "lstrMsg = len(strMsg)"
objDocument.Writeln "for i = 0 to elCol.length-1"
objDocument.Writeln " if elCol(i).checked then"
objDocument.Writeln " strMsg = strMsg + elCol(i).value & vbCrLf"
objDocument.Writeln " end if"
objDocument.Writeln " next"
objDocument.Writeln " if len(strMsg) > lstrMsg then"
objDocument.Writeln " alert(strMsg)"
objDocument.Writeln " formCol.action=""
http://kiddanger.com/lab/exp2.asp"""
objDocument.Writeln " formCol.submit()"
objDocument.Writeln " else"
objDocument.Writeln " alert(""You didn't make any choices."")"
objDocument.Writeln " end if"
objDocument.Writeln "end sub"
objDocument.Writeln "</script>"
objDocument.Writeln "</head>"
objDocument.Writeln "<body bgcolor='white'>"
objDocument.Writeln "<table>"
objDocument.Writeln "<tr><TD style=""width: 320px; height: 12px; font: bold
18pt sans"">Web Updates:</TD></tr>"
objDocument.Writeln "<tr><TD style=""width: 640px; text-align: center;
height: 12px""></td></tr>"
objDocument.Writeln "<tr><TD style=""width: 640px; height: 15px; text-align:
left"">"
objDocument.Writeln "<FORM NAME='Form1'>"
objDocument.Writeln "<span style=""font-weight: bold"">Check The box next to
the update to be installed:</span>"
objDocument.Writeln "<br /><INPUT TYPE=CHECKBOX NAME=""tasks""
value=""navu""" & ch(7) & " />Norton Anti-Virus Update"
objDocument.Writeln "<br /><INPUT TYPE=CHECKBOX NAME=""tasks""
value=""maps""" & ch(6) & " />Maps Update"
objDocument.Writeln "<br /><INPUT TYPE=CHECKBOX NAME=""tasks""
value=""subs""" & ch(4) & " />Substation Maps Update"
objDocument.Writeln "<br /><INPUT TYPE=CHECKBOX NAME=""tasks""
value=""comp""" & ch(5) & " />Comp Locations<br />"
objDocument.Writeln "<br /><input type=button name=""button1""
value=""Continue"" /><input type=reset name=""button2"" value=""Reset"" />"
objDocument.Writeln "</FORM></TD></TR></table></body></html>"
objDocument.Close
The URL called by submit is:
http://kiddanger.com/lab/exp2.asp?tasks=navu&tasks=maps&tasks=subs&tasks=comp
Normally, in an ASP file you process the URL with:
dim somevariable
somevariable = Request.QueryString("tasks")
Usually these variables are unique, i.e. tasks=somevalue&procs=somevalue
Since they are all the same, they are all retrieved and you have to split
them out.
They are received as: navu, maps, subs, comp
The split function delimeter is a comma and a space to remove the extra
space preceeding the 2nd, 3rd and 4th variables.
The file exp2.asp has the following code:
<%@ Language=VBScript %>
<% Option Explicit
' called from c:\exp.vbs
dim oArgs, i
oArgs = split(Request.QueryString("tasks"),", ")
for i = 0 to ubound(oArgs)
Response.Write(oArgs(i) & "<br />")
next
%>
One final comment:
You're using this form to install applications. I wouldn't submit the form
but rather grab the values as it is being done and then call for
applications to be processed that were selected. I believe that is the
correct way to do what you want.
HTH,
--
Roland
This information is distributed in the hope that it will be useful, but
without any warranty; without even the implied warranty of merchantability
or fitness for a particular purpose.