UPDATE: I figured out the answer to my first question. I used two methods, actually. For the "strBoxTitle" variable, I replaced the line:
<b>strBoxTitle</b><p>
with this
<b>
<script>document.write( strBoxTitle )</script>
</b><p>
which correctly displayed the variable's value, rather than its name. This didn’t work for the "strLocalUser" variable, however, because it was inside an input tag. For that one, I added the line
document.getElementById("userid").value = strLocalUser
to my window_OnLoad function, and changed the input tag from
<input id='userid' size=20 class='fixed' value=strLocalUser>
to just
<input id='userid' size=20 class='fixed'>
That also worked, filling in the user input field with the value of "strLocalUser", not to mention preventing me from needing to nest a script tag inside the input tag, which apparently is not allowed.
ORIGINAL QUESTION:
I'm trying to write an HTA file that gets called from a Vbscript file to get user input. The HTA file is called with the command
objWShell.Run ".\UserInput.hta | " & "Please Enter Your Credentials" & _
" | " & strLoginID,1,True
The HTA file "UserInput.hta", which I wrote following examples here in Stack Overflow, is
<!DOCTYPE html>
<html>
<head>
<hta:application
id = oHTA
border = dialog
innerborder = no
caption = yes
sysmenu = no
maximizebutton = no
minimizebutton = no
scroll = no
singleinstance = no
showintaskbar = no
contextmenu = no
selection = yes
/>
<style type='text/css'>
.fixed { font-family:courier new, monospace }
</style>
</head>
<script language="VBScript">
CmdLine = oHTA.commandLine
Params = Split(CmdLine,"|")
strBoxTitle = Params( 1 )
strLocalUser = Params( 2 )
Sub window_OnLoad
Document.Title = strBoxTitle
Window.ResizeTo 400, 200 + 70
Window.MoveTo Window.screen.width / 2 - 200, Window.screen.height / 2 - 200
End Sub
Function SubmitBtn()
Window.Close
End Function
</script>
<body bgcolor=Silver>
<center><form>
<b>strBoxTitle</b><p>
<table>
<tr><td colspan=2 align=left>
Please enter your username and password:<br><br>
</td></tr><tr><td valign=top>
Username:
</td><td>
<input id='userid' size=20 class='fixed' value=strLocalUser>
</td></tr><tr><td valign=top>
Password:
</td><td>
<input type='password' id='passwd' size=20 class='fixed'><p>
</td></tr>
</table>
<p>
<input type='button' value='Submit' id='but0' onclick='SubmitBtn()'>
</form></center>
</body>
</html>
That correctly displays an input box with two input fields. Unfortunately, that's as far as I've gotten. My two questions are:
- How do I get the input box to display the values of the strBoxTitle and strLocalUser variables, instead of the text "strBoxTitle" and "strLocalUser"?
- How do I pass the user-entered values from the input boxes userid and password back to the calling Vbscript?
Thanks in advance for all guidance and suggestions.