Another window.event.srcelement question
It's very helpful to be able to reference a web form field using an windows.event.srcelement pointer, as the field which calls the function may change with each call without requiring code specific to the field:
Dim srcElement
set srcElement = window.event.srcElement
dim strAnswerIn
strAnswerIn=srcElement.Value
This code doesn't care which field called it - it just works (assuming the field supports the value element, of course).
But if the field I wish to manipulate is not the one that called the function, event.srcElement will reference the wrong form field. Sometimes I would like to pass the field name in a parm to the function call instead, yet still reference the field's attributes as I might using srcelement above. So, I'm looking for something like:
sub DoIt(strFormFieldName)
dim srcElement
srcElement = FindFormFieldByName(strFormFieldName)
srcElement.value = "XYZ"
end sub
Note that FormField is not the name of the form field, but rather a pointer like objEvent, and is not the field that called DoIt. So, I might call it like this:
DoIt("fldName")
DoIt("fldAddress")
DoIt("fldCity")
where fldName, fldAddress, and fldCity are the actual form field IDs. I don't care which was passed in the parm, I just want to change its value.
Is it possible to create a windows.event.srcelement like object but based on the name of the field passed, and if so, what's the vbscript function call I'm looking for?
Thanks!
|