View Full Version : Internet Form with Dropdown List using Java/Ajax

12-03-2011, 11:38 AM
How do you select something from a dropdown list that uses Java & maybe Ajax & there’s no <SELECT> in the source? I'm able to populate the input box with the exact info from the dropdown list but because I don't click it in the dropdown list, I get the message "Unable to retrieve employee info".

Done manually, Step 1 is that I start entering an employee ID and a dropdown list appears that will shorten as I enter more of the employee ID. Then I click the name in the dropdown list and the information will move into the input box. Finally, I click on the submit button which opens a Step 2.

I should mention:
1) Clicking the employee in the dropdown list activates a java command called "onclick" which seems to be the equivalent of hitting "enter" and moving the name into the input box.
2) There’s some Ajax code that uses the same id as my input box (ctl00_ContentPlaceHolder1_txtEmpSearch). Not sure what this does, maybe it’s what opens Step2.
3) The dropdown list doesn't seem to come from a <SELECT> list.

Attached is the abbreviated source from an internal network internet form and below is the code I'm using to populate the input box.

Sub ePAF2()
Dim i As Long
Dim objIE As Object
Dim objElement As Object
Dim objCollection As Object

Set objIE = CreateObject("InternetExplorer.Application")
objIE.Visible = True
objIE.navigate "https://www03/ePAF/PAF.aspx?Mode=New (https://www03/ePAF/PAF.aspx?Mode=New)"
Do While objIE.Busy

Set objCollection = objIE.Document.getElementsByTagName("input") 'forms(0) not necessary b/c there's only one form, works with or without
i = 0
While i < objCollection.Length
If objCollection(i).Name = "ctl00$ContentPlaceHolder1$txtEmpSearch" Then
objCollection(i).Value = "123456 - Smith, John)"
End If
i = i + 1

Set objCollection = objIE.Document.getElementsByTagName("input")
i = 0
While i < objCollection.Length
If objCollection(i).Type = "submit" And objCollection(i).Name = "ctl00$ContentPlaceHolder1$btnSearchEmployee" Then
Set objElement = objCollection(i) ' "Search" button is found
End If
i = i + 1

' Clean up
Set objIE = Nothing
Set objElement = Nothing
Set objCollection = Nothing
End Sub