Function Reference


_IEFormElementOptionSelect

Set the value of a specified form element

#include <IE.au3>
_IEFormElementOptionSelect ( ByRef $oObject, $sString [, $iSelect = 1 [, $sMode = "byValue" [, $iFireEvent = 1]]] )

Parameters

$oObject Form Element Object of type "Select Option"
$sString Value used to match element - treatment based on $sMode
$iSelect [optional] specifies whether element should be selected or deselected
    -1 = Return selected state
    0 = Deselect the element
    1 = (Default) Select the element
$sMode [optional] specifies search mode
    "byValue" = (Default) value of the option you wish to select
    "byText" = text of the option you wish to select
    "byIndex" = 0-based index of option you wish to select
$iFireEvent [optional] specifies whether to fire OnChange and OnClick events after changing value
    0 = do not fire OnChange or OnClick event after setting value
    1 = (Default) fire OnChange and OnClick events after setting value

Return Value

Success: the current selected state if $iSelect = -1, else returns 1.
Failure: 0 and sets the @error flag to non-zero.
@error: 3 ($_IEStatus_InvalidDataType) - Invalid Data Type
4 ($_IEStatus_InvalidObjectType) - Invalid Object Type
5 ($_IEStatus_InvalidValue) - Invalid Value
7 ($_IEStatus_NoMatch) - No Match
@extended: Contains invalid parameter number

Remarks

The $iFireEvent parameter is significant only if the form element has an onChange event associated with it.

Related

_IEFormElementCheckBoxSelect, _IEFormElementGetValue, _IEFormElementRadioSelect, _IEFormElementSetValue

Example

Example 1

; Open a browser with the form example, get reference to form, get reference
; to select element, cycle 10 times selecting options byValue, byText and byIndex

#include <IE.au3>

Local $oIE = _IE_Example("form")
Local $oForm = _IEFormGetObjByName($oIE, "ExampleForm")
Local $oSelect = _IEFormElementGetObjByName($oForm, "selectExample")
_IEAction($oSelect, "focus")
For $i = 1 To 10
    _IEFormElementOptionSelect($oSelect, "Freepage", 1, "byText")
    Sleep(1000)
    _IEFormElementOptionSelect($oSelect, "midipage.html", 1, "byValue")
    Sleep(1000)
    _IEFormElementOptionSelect($oSelect, 0, 1, "byIndex")
    Sleep(1000)
Next

_IEQuit($oIE)

Example 2

; Open a browser with the form example, get reference to form, get reference
; to select multiple element, cycle 5 times selecting and then deselecting
; options byValue, byText and byIndex.

#include <IE.au3>

Local $oIE = _IE_Example("form")
Local $oForm = _IEFormGetObjByName($oIE, "ExampleForm")
Local $oSelect = _IEFormElementGetObjByName($oForm, "multipleSelectExample")
_IEAction($oSelect, "focus")
For $i = 1 To 3
    _IEFormElementOptionSelect($oSelect, "Carlos", 1, "byText")
    Sleep(1000)
    _IEFormElementOptionSelect($oSelect, "Name2", 1, "byValue")
    Sleep(1000)
    _IEFormElementOptionSelect($oSelect, 5, 1, "byIndex")
    Sleep(1000)
    _IEFormElementOptionSelect($oSelect, "Carlos", 0, "byText")
    Sleep(1000)
    _IEFormElementOptionSelect($oSelect, "Name2", 0, "byValue")
    Sleep(1000)
    _IEFormElementOptionSelect($oSelect, 5, 0, "byIndex")
    Sleep(1000)
Next

_IEQuit($oIE)

Example 3

; Open a browser with the form example, get reference to form, get reference
; to select element, check to see if the option "Freepage" is selected and
; report result.  Repeat for the option with index 0 and for the option
; with value of 'midipage.html'

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

Local $oIE = _IE_Example("form")
Local $oForm = _IEFormGetObjByName($oIE, "ExampleForm")
Local $oSelect = _IEFormElementGetObjByName($oForm, "selectExample")
If _IEFormElementOptionSelect($oSelect, "Freepage", -1, "byText") Then
    MsgBox($MB_SYSTEMMODAL, "Option Selected", "Option Freepage is selected")
Else
    MsgBox($MB_SYSTEMMODAL, "Option Selected", "Option Freepage is Not selected")
EndIf
If _IEFormElementOptionSelect($oSelect, 0, -1, "byIndex") Then
    MsgBox($MB_SYSTEMMODAL, "Option Selected", "The First (index 0) option is selected")
Else
    MsgBox($MB_SYSTEMMODAL, "Option Selected", "The First (index 0) option is Not selected")
EndIf
If _IEFormElementOptionSelect($oSelect, "midipage.html", -1, "byValue") Then
    MsgBox($MB_SYSTEMMODAL, "Option Selected", "The option with value 'midipage.html' is selected")
Else
    MsgBox($MB_SYSTEMMODAL, "Option Selected", "The option with value 'midipage.html' is NOT selected")
EndIf

_IEQuit($oIE)