get element name in focus

Is it possible in a global method to get the element name that is currently in focus?

I have several fields that when clicked on, I would like them to clear. But in order to do it as a global method, I would need the element name that is in focus. That way I can tell the field to clear it’s information. The other way to do it is to create a different script for each field. May too many scripts to do something soo simple.

Any ideas?

How about if the fields in question have a property that calls a global method that includes:

var fieldName = application.getMethodTriggerElementName();
(where name of element = name of dataprovider)?

You’ll need to load the current form into a variable too:

var formName = application.getMethodTriggerFormName();

then do your thing like :

forms[formName][fieldName] = “”

That’s just the general idea; actual code will vary. Check Servoy Mag for more & better info; David Workman is the King of Abstraction.

Hello,

Jim is on the right track. The following code gets us closer I think:

// this script should be attached to an onFocusGained event (make sure you've set the "name" property)
var formName    = application.getMethodTriggerFormName();
var elementName = application.getMethodTriggerElementName();

// to make any changes to the field, we need the dataprovider name associated with the element name
var fieldName   = forms[formName].elements[elementName].getDataProviderID();

// clearing the field
forms[formName].controller.setDataProviderValue(fieldName, null);

I’m trying to become the Clown Prince of Abstraction :)