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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

open a child window HTA

Status
Not open for further replies.

bertieuk

IS-IT--Management
Jun 1, 2004
175
I am just getting into HTA. I've been using vbs for approx 2 years.

I am trying to convert an existing vbs script to HTA.

I want to open a child window that will ask for both a user name and password should the script detect that the server I connect to uses different credentials to my local.

I need this child window to pass the server, username and password back into the script section.

Can anyone give me guidance.

Simon
 
There are several ways. I normally use window.showModalDialog to show the dialog. The second parameter is normally passed by reference so you can pass in values as well as return values. It doesn't like arrays so the parameters have to be passed in as a class.

In the dialog, use window.dialogArguments to get at the parameters. A simple version of your requirement follows
Code:
<html>
<head>
<title>HTA Test</title>
<HTA:APPLICATION
     APPLICATIONNAME="Login Launcher"
     BORDER="thick"
     CAPTION="yes"
     MAXIMIZEBUTTON="yes"
     MINIMIZEBUTTON="yes"
     SCROLL="yes"
     SHOWINTASKBAR="yes"
     SINGLEINSTANCE="yes"
     SYSMENU="yes"
     WINDOWSTATE="normal"
>
<script language="vbscript">
   ' Class for passing in parameters
   class ClsLoginParam
      dim m_login
      dim m_password
   end class
   
   sub Login_OnClick
      dim loginParam
      ' Create something for the dialog to return
      set loginParam = new ClsLoginParam
      window.showModalDialog "parchildLogin.htm", loginParam, "dialogHeight:120px;dialogWidth:300px;status:no;resizable:no;scroll:no"
      ' Display the returned parameters
      MsgBox loginParam.m_login & " " & loginParam.m_password
   end sub
   
   sub Close_OnClick
      Window.parent.close
   end sub
</script>
</head>
<body onload="window.resizeTo 200,100">
<input type="button" name="Login" value="Login">
<input type="button" name="Close" value="Close">
</body>
</html>
The dialog
Code:
<HTML><head>
<title>Title</title>
<script language="vbscript">
   ' Note - class does not need to be defined here
   sub Login_OnClick
      set loginParam = window.dialogArguments
      loginParam.m_login = logintxt.value
      loginParam.m_password = passwordtxt.value
      window.parent.close
   end sub
   
   sub Cancel_OnClick
      window.parent.close
   end sub
</script>
</head>
<body>
<table cellspacing=0 border=0 cellpadding="5">
  <tr><td>Login</td><td><input name="logintxt" type="text" size="20"></td></tr>
  <tr><td>Password</td><td><input name="passwordtxt" type="password" size="20"></td></tr>
  <tr>
    <td><input type="button" name="Login" value="Login" ID=Button1></td>
    <td><input type="button" name="Cancel" value="Cancel" ID=Button2></td>
  </tr>
 </table>
</body></HTML>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top