Function Reference


_IEFormElementSetValue

Set the value of a specified Form Element

#include <IE.au3>
_IEFormElementSetValue ( ByRef $oObject, $sNewValue [, $iFireEvent = 1] )

Parameters

$oObject Object variable of an InternetExplorer.Application, Form Element object
$sNewValue The new value to be set into the Form Element
$iFireEvent [optional] specifies whether to fire an OnChange event after changing value
    0 = Do not fire OnChange or OnClick event after setting value
    1 = (Default) fire OnChange and OnClick event after setting value

Return Value

Success: 1.
Failure: 0 and sets the @error flag to non-zero.
@error: 2 ($_IEStatus_COMError) - COM Error in Object reference
3 ($_IEStatus_InvalidDataType) - Invalid Data Type
4 ($_IEStatus_InvalidObjectType) - Invalid Object Type
@extended: Contains invalid parameter number

Remarks

While all Form Elements have a value, only text oriented elements use their value attribute in an obvious fashion (type text, textarea, hidden, password and file).
The value of other form elements does not affect what is displayed in the user interface, but rather the value that is returned by the element when it is selected or activated.

See _IEFormElementOptionSelect(), _IEFormElementCheckBoxSelect(), _IEFormElementRadioSelect() and _IEFormImageClick() for more information.

Note: You cannot use _IEFormElementSetValue() to set the value of an INPUT TYPE=FILE element. Browser security restrictions prevent this element from being scripted. See the example below for a workaround.

Related

_IEFormElementCheckBoxSelect, _IEFormElementGetCollection, _IEFormElementGetObjByName, _IEFormElementGetValue, _IEFormElementOptionSelect, _IEFormElementRadioSelect

Example

Example 1

; Open a browser with the form example, set the value of a text form element

#include <IE.au3>

Local $oIE = _IE_Example("form")
Local $oForm = _IEFormGetObjByName($oIE, "ExampleForm")
Local $oText = _IEFormElementGetObjByName($oForm, "textExample")
_IEFormElementSetValue($oText, "Hey! This works!")

Example 2

; Get a reference to a specific form element and set its value.
; In this case, submit a query to the Google search engine

#include <IE.au3>

Local $oIE = _IECreate("http://www.google.com")
Local $oForm = _IEFormGetCollection($oIE, 0)
Local $oQuery = _IEFormElementGetCollection($oForm, 4)
_IEFormElementSetValue($oQuery, "AutoIt IE.au3")
_IEFormSubmit($oForm)

Example 3

; Set the value of an INPUT TYPE=TEXT element using Send()

#include <IE.au3>

Local $oIE = _IE_Example("form")
Local $oForm = _IEFormGetObjByName($oIE, "ExampleForm")
Local $oInputFile = _IEFormElementGetObjByName($oForm, "textExample")

; Assign input focus to the field and then send the text string
_IEAction($oInputFile, "focus")

; Select existing content so it will be overwritten.
_IEAction($oInputFile, "selectall")

Send("This works")

Example 4

; Set the value of an INPUT TYPE=TEXT element on an invisible
; window using ControlSend()

#include <IE.au3>
#include <MsgBoxConstants.au3>

Local $oIE = _IE_Example("form")

; Hide the browser window to demonstrate sending text to invisible window
_IEAction($oIE, "invisible")

Local $oForm = _IEFormGetObjByName($oIE, "ExampleForm")
Local $oInputFile = _IEFormElementGetObjByName($oForm, "textExample")

; Assign input focus to the field and then send the text string
_IEAction($oInputFile, "focus")

; Select existing content so it will be overwritten.
_IEAction($oInputFile, "selectall")

; Get a handle to the IE window.
Local $hIE = _IEPropertyGet($oIE, "hwnd")
ControlSend($hIE, "", "[CLASS:Internet Explorer_Server; INSTANCE:1]", "This works")

_IEAction($oIE, "visible")
MsgBox($MB_SYSTEMMODAL, "Success", "Value set to 'This works'")