Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB 2005 > Visual Basic 2005 Basics
|
Visual Basic 2005 Basics If you are new to Visual Basic programming with version 2005, this is the place to start your questions. For questions about the book: Beginning Visual Basic 2005 by Thearon Willis and Bryan Newsome, ISBN: 0-7645-7401-9 please, use this forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Visual Basic 2005 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 16th, 2007, 05:09 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 428
Thanks: 57
Thanked 2 Times in 2 Posts
Default 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!





Similar Threads
Thread Thread Starter Forum Replies Last Post
Forward Mouse event in Main window to its controls guntank C# 2005 0 November 15th, 2006 09:32 PM
on window unload event in javascript. babu17 Classic ASP Basics 1 April 15th, 2006 05:48 AM
Is there an Event for resizing the main XL window? labdad Excel VBA 2 January 6th, 2006 07:23 PM
Handling window unload event MurthyGarimella Javascript 2 June 30th, 2004 10:59 AM
Detect srcElement on Embedded Image TSEROOGY Javascript 8 August 29th, 2003 01:42 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.