Share via


htmlFor Property

Returns or sets a String that represents the object that is bound to a script, label, or form. Corresponds to the for attribute for the SCRIPT, LABEL, and FORM elements.

expression.htmlFor

*expression   * Required. An expression that returns one of the objects in the Applies To list.

Remarks

The for attribute of a SCRIPT, LABEL, or FORM element contains a unique identifier for a control on a page. For example, you might have an input box on a page with an id attribute of "email" and a text label next to it that says, "Please enter your email address:". When the for attribute of the LABEL element is set to be equal to the id attribute of the INPUT element, if a user clicks on the label when the page is viewed in the browser, the browser will give the corresponding INPUT element the focus. The following HTML code illustrates this.

<p><label id="lblemail">email address</label></p>
<p><input type="text" id="email"></p>

Example

The following example assigns an access key and specifies the corresponding control on the page to which the LABEL element applies. You can run this example against the above HTML code without error. Otherwise, this example assumes that you have a LABEL element in the active document with an id attribute of "lblemail".

Dim objLabel As FPHTMLLabelElement

Set objLabel = ActiveDocument.all.tags("label").Item("lblemail")
objLabel.accessKey = "e"
objLabel.htmlFor = "email"

Applies to | FPHTMLLabelElement Object | FPHTMLScriptElement Object | IHTMLLabelElement Object | IHTMLScriptElement Object