# Dropdown box and changeData Event

**URL:** <https://forum.servoy.com/t/dropdown-box-and-changedata-event/5043>\
**Category:** Classic Servoy\
**Created:** [November 10, 2005, 3:22pm UTC](https://forum.servoy.com/t/dropdown-box-and-changedata-event/5043 "2005-11-10T15:22:21Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![MerMer](https://avatars.discourse-cdn.com/v4/letter/m/e36b37/32.png) [@MerMer](https://forum.servoy.com/u/MerMer)\
**Post date:** [November 10, 2005, 3:22pm UTC](https://forum.servoy.com/t/dropdown-box-and-changedata-event/5043/1 "2005-11-10T15:22:21Z")

</div>

As a newbie I am still finding my way around scripting.

I have a drop down box which displays as Null and has a drop down list of two values (“Action Required” and “No Action”).

If I am changing the list from the Null value to any of the other values I want to ammend some fields on another form. If I am changing from anything other than the Null value I don’t want to make any changes to the corresponding form.

I have created the scrip below and am using the “ChangeData” event

However, I cannot capture the “null” value because the timing of the Change Data event seems to be after the datachange, rather than capture the information prior to the change. Therefore, on the current scrip the changes take place on the corresponding form every time I change the dropdown value instead of just when I change the list from Null.

Is there a way around this?

> var dropDownChange = email\_to\_actionid.actionornot
> 
> application.output (dropDownChange);  
> if (dropDownChange = ‘null’ )  
> {  
> //look for matching record in the actions form based on emailid in the current form  
> var emailID = emailid;  
> application.output (emailID)  
> forms.actions.controller.find();  
> forms.actions.emailid = emailID;  
> forms.actions.controller.search();
> 
> //set actiontrigger, compnanyid, actionrequired fields in the matching record of the actions form.  
> forms.actions.controller.setDataProviderValue(‘actiontrigger’,‘email’); //action trigger is created from email  
> forms.actions.controller.setDataProviderValue(‘actionrequired’,‘See Email ID’ + emailID );
> 
> //remove the foundset  
> forms.actions.controller.loadAllRecords()
> 
> }

---

<div class="post-metadata">

**Author:** ![patrick](https://avatars.discourse-cdn.com/v4/letter/p/b2d939/32.png) [@patrick](https://forum.servoy.com/u/patrick)\
**Post date:** [November 10, 2005, 3:30pm UTC](https://forum.servoy.com/t/dropdown-box-and-changedata-event/5043/2 "2005-11-10T15:30:28Z")

</div>

To capture the NULL, you need to capture the value before the datachange. That can be done by using

```auto
var oldValue = arguments[0];

```

---

<div class="post-metadata">

**Author:** ![MerMer](https://avatars.discourse-cdn.com/v4/letter/m/e36b37/32.png) [@MerMer](https://forum.servoy.com/u/MerMer)\
**Post date:** [November 10, 2005, 4:06pm UTC](https://forum.servoy.com/t/dropdown-box-and-changedata-event/5043/3 "2005-11-10T16:06:02Z")

</div>

Patrick,

Thanks for you help - but I’m not sure how to apply your advice. I’m new to programming so nothing is intuitive.

I tried the line:-

> var dropDownChange = email\_to\_actionid.actionornot [0];

but it simply returns the first letter of the field after it has changed.

MerMer

---

<div class="post-metadata">

**Author:** ![bcusick](https://avatars.discourse-cdn.com/v4/letter/b/ed8c4c/32.png) [@bcusick](https://forum.servoy.com/u/bcusick)\
**Post date:** [November 10, 2005, 4:39pm UTC](https://forum.servoy.com/t/dropdown-box-and-changedata-event/5043/4 "2005-11-10T16:39:26Z")

</div>

You must literally use arguments[0]. That’s the argument passed by Servoy into a method on an onDataChange event - that contains the old value of the field.

```auto
var oldValue = arguments[0]

if(!oldValue)
{
    //oldValue was null or empty
    //YOUR CODE HERE
}
else
{
    //oldValue was NOT null or empty
    //YOUR CODE HERE
}

```

Hope this helps.

---

<div class="post-metadata">

**Author:** ![MerMer](https://avatars.discourse-cdn.com/v4/letter/m/e36b37/32.png) [@MerMer](https://forum.servoy.com/u/MerMer)\
**Post date:** [November 10, 2005, 6:10pm UTC](https://forum.servoy.com/t/dropdown-box-and-changedata-event/5043/5 "2005-11-10T18:10:15Z")

</div>

Bob,

Many thanks - that makes it clear. I struggled to find the relevant info in the documention as a search on “arguments” brings up alot of hits. Is there a particular section I should be looking at in the manual for background on this?

MerMer

---

<div class="post-metadata">

**Author:** ![patrick](https://avatars.discourse-cdn.com/v4/letter/p/b2d939/32.png) [@patrick](https://forum.servoy.com/u/patrick)\
**Post date:** [November 11, 2005, 8:36am UTC](https://forum.servoy.com/t/dropdown-box-and-changedata-event/5043/6 "2005-11-11T08:36:43Z")

</div>

“arguments” is an Array that is used when you pass parameters to a method. You can do something like this:

Method addOne()

```auto
var inputNumber = arguments[0];
return inputNumber + 1;

```

Method doSomething()

```auto
var aNumber = 47;
aNumber = addOne(aNumber); // this will call method addOne passing aNumber; since addOne will simply add 1, aNumber will be 48.

```

If you want to pass more than one parameter, you do the call

```auto
addOne(param1, param2, param3)

```

and in addOne

```auto
var firstParam = arguments[0];
var secondParam = arguments[1];
var thirdParam = arguments[2];

```

Hope this helps.

---

<div class="post-metadata">

**Author:** ![MerMer](https://avatars.discourse-cdn.com/v4/letter/m/e36b37/32.png) [@MerMer](https://forum.servoy.com/u/MerMer)\
**Post date:** [November 11, 2005, 4:59pm UTC](https://forum.servoy.com/t/dropdown-box-and-changedata-event/5043/7 "2005-11-11T16:59:21Z")

</div>

Patrick,

Many thanks.

What I was confused about was why argument [0] refers to a previous value when using the onDataChange event. I can’t see any reference to this in the manual.

MerMer

---

<div class="post-metadata">

**Author:** ![kazar](https://avatars.discourse-cdn.com/v4/letter/k/3be4f8/32.png) [@kazar](https://forum.servoy.com/u/kazar)\
**Post date:** [November 12, 2005, 3:35pm UTC](https://forum.servoy.com/t/dropdown-box-and-changedata-event/5043/8 "2005-11-12T15:35:14Z")

</div>

Hi MerMer –

I can identify with the struggle to learn the components of javascript, and to figure out how to apply them within a Servoy solution. There is a lot to javascripting and the “whole enchillada” could never be included in the Servoy Documentation.

A search in Acrobat on the Servoy Developer manuals goes pretty quickly. For example, you can search for “arguments[0]” and determine pretty quickly that this string is not explicitly explained therein. What I’ve been doing as my next strategy is to Google the phrase. (What the heck did we ever do before Google?!). There is so much information, and so many tutorials, on javascript out on the Web it will boggle your mind. The problem is twofold: (1) your Google hit-list will likely be so long it is a challenge to sift through it, and (2) almost paradoxically, javascript components can, it seems, be “mixed ‘n’ matched” so many ways when you are writing your functions, that - in spite of all those Google hits and tutorials - it might be hard to find an exact answer to your question. But gradually one begins to assimilate and process all that info so that one starts to “get it”.

I have also found it very helpful to keep a couple of books around on javascripting. Just about everything in a javascript will apply to using it in Servoy solutions (except, as I understand it anyhow, the document and window classes).

Here is what I’ve learned from my explorations regarding this arguments[0] thingie:

- ‘arguments’ is an array of values that is passed to a function
- javascript starts counting at 0, so the first value in an array is numbered 0
- when you use ‘arguments[0]’ you are telling the function to evaluate (or return) the first value that was passed to it
- the old value of a field is passed through when you use the onDataChange event … therefore arguments[0] will recall that value for further action in the method you have called

There may well be instances of non-standard vocabulary in my description, but I’m hoping that coming from another beginner javascripter, and therefore in “Beginner Javascripter Speak”, maybe it helps?

kazar
