Link to home
Create AccountLog in
Avatar of MitchellVII
MitchellVIIFlag for United States of America

asked on

How to do refer to HTML elements in vbScript?

Hi,

I am conversant in Visual Basic from working on MS Access and just learning VBScript (which seems quite similar).

In Visual Basic, if I want to refer to a control on a form by name, I first establish the Form as an object, then use the name like so:

myForm.controls('myControl").value = "Hello World!"

Let's say that I have a Function in VBScript where I want to pass the id of an input element and then asign a value to it.  What wording would I use?

Function chgValues(strID)
Avatar of MitchellVII
MitchellVII
Flag of United States of America image

ASKER

I guess what I am asking is, what is the VBScript equivalent of the JavaScript document.getElementById?
Here's the function and how I think it "should" work, but it doesn't :(

'FUNCTION - Assign Value to Input from Select Choice:
Function strSelectSet(idText,objSelect,strType)

Select case strType
      case "text"
            document.getElementById(idText).value = objSelect.options(text.selectedIndex).text
      case "value"
            document.getElementById(idText).value = objSelect.options(text.selectedIndex).value
end select
            
End Function

The first case assigns the .text value of the option and the second case assigns the .value value of the option.
ASKER CERTIFIED SOLUTION
Avatar of golfDoctor
golfDoctor

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
On my webform, I am attempting to call this from a <select> element like so:

onChange="strSelectSet('CommuteCity1',this,'text')

Does nothing.
golf,

Ah ok, that's likely my problem.  Sorry, I am such a noob at all this.

So I can't use VBScipt for anything on an ASP Page done by the user as the fill out the form, that all has to be JavaScript?