1) Yes that is correct, if it returns true, it was able to select the radio with that value, if not, it returns false.
2) You have to go by the value of the radio instead of its name since the name is shared between the multiple radio buttons that are for the same option. We could create a function to refer to it by name and index.
Lets say we have:
Code:
<input type="RADIO" name="prefix" value="Mr" >Mr.
<input type="RADIO" name="prefix" value="Mrs" >Mrs.
<input type="RADIO" name="prefix" value="Miss" >Miss
<input type="RADIO" name="prefix" value="Ms" >Ms
You see that we cannot tell the code to click the radio named "prefix" because there are 4 of them with that name. So, we could tell it to click the radio with the value of "Mr", "Mrs", "Miss", or "Ms".
However we could tell the code to click the 3rd radio button with the name "prefix", or just the Nth radio button on the form regardless of name (as it appears in source) by making another function like this:
Code:
Function SelectRadioByIndex(oDocAll, iRadioIndex, sRadioName)
Dim iCnt
Dim sValue
Dim sType
With oDocAll
On Error Resume Next
For i = 0 To (.Length - 1)
sValue = Empty
sType = Empty
sValue = .Item(i).Value
sType = .Item(i).Type
If Not IsEmpty(sValue) And Not IsEmpty(sType) Then
If sType = "radio" Then
If Not IsEmpty(sRadioName) Then
If LCase(sRadioName) = LCase(.Item(i).Name) Then
iCnt = iCnt + 1
If iRadioIndex = iCnt Then
On Error GoTo 0
.Item(i).Click
SelectRadioByIndex = True
Exit Function
End If
End If
Else
iCnt = iCnt + 1
If iRadioIndex = iCnt Then
On Error GoTo 0
.Item(i).Click
SelectRadioByIndex = True
Exit Function
End If
End If
End If
End If
Next
Stop
On Error GoTo 0
End With
SelectRadioByIndex = False
End Function
You can then use this to click the radio button:
Code:
If SelectRadioByIndex(oIE.Document.All, 3, "prefix") = True Then MsgBox "SelectRadioByIndex successfully clicked 3rd 'prefix' radio button"
If SelectRadioByIndex(oIE.Document.All, 2, empty) = True Then MsgBox "SelectRadioByIndex successfully clicked the 2nd radio button on page"
The first example clicks the Nth radio button named "prefix", the second example clicks the Nth radio button on the whole page.
Having both the first function and this new function available pretty much gives you all the flexibility you're going to get for clicking a radio button programatically.