Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Access an HTML object by name

Status
Not open for further replies.
Nov 14, 2000
31
AU
I want to pass a HTML object name to a function to perform the following task.

It won't work because I don't know how to set the reference to the object.

Javascript has the getElement command. Does vbscript has something similar?

Function AddOptionToSelectList(strSelectListName,strOptionValue, strOptionText)

Set objOption = document.CreateElement("OPTION")
objOption.Value = strOptionValue
objOption.Text = strOptionText

'PROBLEM OCCURS HERE
'strSelectListName can't be a varible. If I put the select
'list name in manually it works.

strSelectListName.add objOption

Set objOption = Nothing

End Function
 
Looks messy and there is probably a much better way but hey it works.

Function AddOptionToSelectList(strSelectListName,strOptionValue, strOptionText)

Dim objectIndex

On Error Resume Next

For i = 0 To Document.all.Length - 1

If Lcase(Document.All.Item(i).name) = Lcase(strSelectListName) Then

If err.Number <> 0 Then
err.Clear
Else
objectIndex = i
End If

End If

Next

On Error GoTo 0


Set objOption = document.CreateElement(&quot;OPTION&quot;)
objOption.Value = strOptionValue
objOption.Text = strOptionText
Document.All.item(objectIndex).add objOption
Set objOption = Nothing

End Function
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top