Microsoft HTA/Buttons and forms

Before learning how to use VBScript in your HTA programs, you should know about HTML buttons and forms. Forms are declared with the  tag. There are two ways to send form data, GET and POST. POST is more secure, but the difference does not matter in offline HTA programs. A form tag is declared similarly to. The  attribute can contain a JavaScript function which can let you handle the form data after it is submitted. The  attribute is the method (GET or POST) used to send the form data. Finally, the  attribute is used in JavaScript to access the contents of the form.

Forms use  and   tags to display their interface to the user. An  tag contains three required attributes and multiple other optional attributes:


 * : The type of control. Some important ones are  for submit buttons,   for text fields, and   for passwords and sensitive information. Values explained later on.
 * : The ID your control has. Must be different from other control IDs in the same form.
 * : A control's name. You can use the name of a control to access it within If you do not know what to set this to, just set it to the control's ID.
 * : (Optional) The size of your control. This attribute is for text controls.
 * : (Optional) The text that appears when a text control is empty.
 * : (Optional) The selected option in a control that is set when the form is initially loaded.

The only attribute required for a  field is. Set the value of this attribute to the matching control's ID.

You can put  tags in between two controls to stack them vertically.

Once a form is submitted, you can handle the form using JavaScript with. Make sure to use the values of the  attributes of the form and control you want to query! For example, in the code sample below, the value of the form's  attribute is   and the value of the control's   attribute is.

Types of Form Controls
These form control types can be used as an argument to the  attribute of a   element.


 * : Shows a "Submit" button which calls the function in the  attribute of the   element when pressed.
 * : Shows a "Reset" button which resets the values of all form controls in the  element when pressed.
 * : Basic text field.
 * : Text field which hides its value.
 * : Text field with validation for email addresses.
 * : Check box.
 * : File upload button.
 * : Radio button.

There are other  attribute values but they are less common. You can search for them if you would like to learn about the other  attribute values.

When the  attribute is used on a control which is a   or   button control, it changes the text inside of the button.

Buttons
Buttons are declared using the  element. The most important attribute is, which triggers a JavaScript or VBScript function when the button is clicked. A button which says "Click Me" may look like.

Advanced Controls
This section explains the text area element, grouping form controls with the  and   elements, and the usage of the   control.

Text Areas
The  element is a way to make a large text field with vertical size. It has many of the same attributes as the  element, but the   attribute is replaced with the   attribute. There is a new attribute for vertical size called. A simple text area may look like.

Grouping Controls
Form controls can be grouped using the  element. It has no attributes and it is a container for all of the form controls inside of the group. The first element inside of a  should be the   element. The title of the group of controls should be placed inside of the  element. An example of control grouping is shown below.

Dropdown Boxes
Dropdown controls are fairly complex compared to other controls. Instead of the  element, you use the   element for dropdown boxes. The  and   attributes are required for the   element. Inside of the  element, you can put   elements which can be selected by the user. The content between the opening and closing tags is the name of the dropdown option, and the required  attribute is required for   elements and serves a similar purpose to the   attribute. Optionally, you can group dropdown options by using  elements containing the group of options. elements require the  attribute, which is the label displayed above the group of options. An example of a form using dropdown menus is below.