Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Pass form value to vbs 1

Status
Not open for further replies.

DebbieDavis

Programmer
Jun 7, 2002
146
0
0
US
Hi there, I've searched but do not know how to do this. and I'm sure it's elementary but I'm not that familiar with wscript and the syntax. I have a simple html form:
Code:
<form name=frmTest action=test.vbs>
<select name=location>
<option value=1>Front Desk
<option value=2>Yard
<option value=3>Accounting
</select></form>
I'm trying to pass the form values to the vbs so we can run a script based on the location chosen. How do I read the form value once it gets to test.vbs? Once I can do that the rest of my code will work. Many thanks for your input.
 
An excellent question Sheco.

The way form data is obtained in VBScript varies. If we are talking about client script within the HTML page one mechanism applies. If it is server-side script another must be used. A third possibility is a separate WSH script on the client system. The 4th way might be a WSH script hosting the page within an automated IE instance.

So it becomes really important to know where this "test.vbs" is going to be run, and how.
 
Thanks. No, I'm not passing these values to or from an asp page. I'm passing them to a vbs script file via a simple html form. To further explain, we are extracting system data with wmi from all of our computers via a script. But instead of doing it for ALL of the computers we would like to choose the location. i.e. Accounting has IP addresses x, y and z so I could run the script on only x, y and z. The data is extracted from the computers chosen and written to a SQL database. That said, maybe there is a way to create a listbox via wscript? Since I couldn't figure out how to do that, I thought an html form would work but I don't know how to recognize the values after they are passed to test.vbs. Thanks again anyway.

 
Ahh, what you really want is an HTA. This is a form of "GUI" desktop script.

HTML Applications

This is basically written as an HTML page with embedded script blocks (JScript or VBScript in most cases), saved to disk locally with the file extension .HTA instead of .HTM/.HTML, etc. It runs in the same sort of security environment as a WSH script, and can perform most scripting tasks without any security warnings. HTAs can also use the [tt]<HTA:Application>[/tt] tag to offer more control over the window the GUI displays in.

The script blocks can be external (.VBS) files that are included using the HTML [tt]<SCRIPT>[/tt] tag or simply written inline within the .HTA file itself.


In an HTA you normally just leave the [tt]<FORM>[/tt]'s [tt]action[/tt] attribute at its default value. Instead of a [tt]type=submit[/tt] button you just use a normal button. This button's [tt]onclick[/tt] event handler then performs the form-processing actions.

Within the [tt]onclick[/tt] handler you access form elements by syntax like [tt]frmTest.location.value[/tt].

Normally elements are named using the [tt]id[/tt] attribute instead of [tt]name[/tt], whch is really meant for use in submitting data to a server. IE will normally try to coerce a [tt]name[/tt] value into the [tt]id[/tt] attribute though, so typically using [tt]name[/tt] will work... until it doesn't! ;-)

Simple example samp.hta:
Code:
<HTML>
  <HEAD>
    <SCRIPT language=VBScript>
      Sub btnGo_onclick()
        'Logic to process the form goes in here.
        MsgBox frmTest.location.value
      End Sub
    </SCRIPT>
  </HEAD>
  <BODY>
    <FORM id=frmTest>
      <SELECT id=location>
        <OPTION value=1>Front Desk
        <OPTION value=2>Yard
        <OPTION value=3>Accounting
      </SELECT>
      <INPUT type=button id=btnGo value=Go>
    </FORM>
  </BODY>
</HTML>
 
Wow, that's really neat. Thanks so much. I did not know about that. Please forgive my ignorance. But how still do I process the rest of my code? Do I put it inside the script tags, database connection and all? Many many thanks for your help.
 
I should add that many people write WSH scripts that automate an instance of IE. This is sort of "inside out" from the HTA approach: instead of an HTML page containing script, you have a WSH script that embeds an HTML page.

This allows you to use IE as a sort of flexible dialog type or "super InputBox."

Access to form elements in such a "dialog" is much like that from script within a web page (or HTA). One article on this is Using Forms in VBScript/JScript but I consider this a lot more work than just writing an HTA. Others swear by this method though, and it has some advantages.
 
Thank you SO MUCH Dilettante. I got the script from that link you sent, modified it with pieces of my own script and it's working exactly as I wanted. I can't begin to thank you enough!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top