# get element name in focus

**URL:** <https://forum.servoy.com/t/get-element-name-in-focus/6581>\
**Category:** Classic Servoy\
**Created:** [October 12, 2006, 6:08pm UTC](https://forum.servoy.com/t/get-element-name-in-focus/6581 "2006-10-12T18:08:11Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![elyod\_72](https://avatars.discourse-cdn.com/v4/letter/e/ed655f/32.png) [@elyod\_72](https://forum.servoy.com/u/elyod_72)\
**Post date:** [October 12, 2006, 6:08pm UTC](https://forum.servoy.com/t/get-element-name-in-focus/6581/1 "2006-10-12T18:08:11Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![jim](https://avatars.discourse-cdn.com/v4/letter/j/ac91a4/32.png) [@jim](https://forum.servoy.com/u/jim)\
**Post date:** [October 12, 2006, 6:58pm UTC](https://forum.servoy.com/t/get-element-name-in-focus/6581/2 "2006-10-12T18:58:05Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![chartpacs](https://avatars.discourse-cdn.com/v4/letter/c/8edcca/32.png) [@chartpacs](https://forum.servoy.com/u/chartpacs)\
**Post date:** [October 13, 2006, 6:38am UTC](https://forum.servoy.com/t/get-element-name-in-focus/6581/3 "2006-10-13T06:38:27Z")

</div>

Hello,

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

```auto
// 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 ![:)]( "Smile")
