Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

trouble w/ htm form in vbs

3 views
Skip to first unread message

mishkare

unread,
Dec 28, 2003, 2:42:12 AM12/28/03
to
Hi,
I'd be grateful for any help.

I have a script that CREATES a page in IE.
on this page are 4 check boxes a submit and a reset.
reset works but I am having a hard time getting submit to work correctly.
when submit is clicked it either does nothing or sets IE to a blank
page(about:blank)
I am trying to use the example below in my script because it does not use
the POST or GET method of passing variables to another page.

<SCRIPT LANGUAGE="VBSCRIPT">
<!--
Sub Button1_onclick
Dim Selections, Count
Count = 0
If Form1.elements(0).checked = True Then
Selections = "Information systems"
Count = Count + 1
End If
If ...
alert "You checked the following choice(s): " & Selections
End If
End Sub
-->
</SCRIPT>
<FORM NAME="Form1">
<B>Choose the areas you are interested in</B>
<BR><INPUT TYPE=CHECKBOX NAME="chkIS"> Information systems
<BR><INPUT TYPE=CHECKBOX NAME="chkSE"> Systems integration
<BR><INPUT TYPE=CHECKBOX NAME="chkSA"> System administration
<BR><INPUT TYPE=CHECKBOX NAME="chkMgmt"> Management
<BR><INPUT TYPE=BUTTON NAME="Button1" VALUE="Continue">
</FORM>

ETC....

.
I can find lots of examples of using vbs in htm pages like above...
...But I can't find much on using vbs to create a form in IE.

Can I set the VALUE of the submit button to point to a function? How?


Roland Hall

unread,
Dec 28, 2003, 6:14:14 AM12/28/03
to
"mishkare" wrote:
> I have a script that CREATES a page in IE.
> on this page are 4 check boxes a submit and a reset.
> reset works but I am having a hard time getting submit to work correctly.
> when submit is clicked it either does nothing or sets IE to a blank
> page(about:blank)

<!--SNiP-->

Setting your checkboxes with all the same name allows you to process them as
an array, like a list box. I don't normally write client-side vbscript but
this should be sufficient. Anyone who wants to offer a better solution can.
http://kiddanger.com/lab/vbsform.html

> Can I set the VALUE of the submit button to point to a function? How?

How about form1_onSubmit()?

--
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.

mishkare

unread,
Dec 28, 2003, 1:16:44 PM12/28/03
to
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.

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)
Loop
dim ch(8)
Set objDocument = objExplorer.Document
objDocument.Open
objDocument.Writeln "<html><head><title>Web Laptop Updates</title></head>"
objDocument.Writeln "<body bgcolor='white'>"
objDocument.Writeln "<TD width='320' height='12'><b><font face='Times New
Roman' size='5'>Web Updates:</font></b></TD>"
objDocument.Writeln "<TD width='640' align='center' height='12'><p>"


objDocument.Writeln "<p align='left'><TD width='640' height='15'</P>"
objDocument.Writeln "<FORM NAME='Form1'>"
objDocument.Writeln "<b>Check The box next to the update to be installed:
</p>"
objDocument.Writeln "<INPUT TYPE=CHECKBOX NAME='NAVU' value='Yes'" &ch(7)&
">Norton Anti-Virus Update"
objDocument.Writeln "<BR><INPUT TYPE=CHECKBOX NAME='Maps' value='Yes'"
&ch(6)& ">Maps Update"
objDocument.Writeln "<BR><INPUT TYPE=CHECKBOX NAME='Subs' value='Yes'"
&ch(4)& ">Substation Maps Update"
objDocument.Writeln "<BR><INPUT TYPE=CHECKBOX NAME='comp' value='Yes'"
&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></p></b></TD></TR>"
sub form1_onSubmit()
dim formCol, elCol, strMsg, lstrMsg
set formCol = document.forms("form1")
set elCol = formCol.dept
strMsg = "You checked the following choice(s):" & vbCrLf
lstrMsg = len(strMsg)
for i = 0 to elCol.length-1
if elCol(i).checked then
strMsg = strMsg + elCol(i).value & vbCrLf
end if
next
if len(strMsg) > lstrMsg then
alert(strMsg)
else
alert("You didn't make any choices.")
end if
end sub

"Roland Hall" <nobody@nowhere> wrote in message
news:O6yqa7Sz...@TK2MSFTNGP11.phx.gbl...

Roland Hall

unread,
Dec 29, 2003, 6:16:56 AM12/29/03
to
"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,

0 new messages