# Get selected value from combobox

**URL:** https://forum.servoy.com/t/get-selected-value-from-combobox/9599
**Category:** Classic Servoy
**Created:** [September 16, 2008, 4:00pm UTC](https://forum.servoy.com/t/get-selected-value-from-combobox/9599 "2008-09-16T16:00:36Z")
**Posts on this page:** 11
**Page:** 1

<div class="post-metadata">

### Author: ![kschuster](https://avatars.discourse-cdn.com/v4/letter/k/9d8465/32.png) [@kschuster](https://forum.servoy.com/u/kschuster)
#### Post date: [September 16, 2008, 4:00pm UTC](https://forum.servoy.com/t/get-selected-value-from-combobox/9599/1 "2008-09-16T16:00:36Z")

</div>

I have this function that loads the valuelist for a combobox. How do I get the selected id value from the combo so I can set a variable with it.

function refreshStateList()  
{

var maxReturedRows = 60;  
var query = ‘select stateName, StateID from tbl\_states’;  
var dataset = databaseManager.getDataSetByQuery(controller.getServerName(), query, null, maxReturedRows);  
var nameArray = dataset.getColumnAsArray(1);//put 1st column in array  
var idArray = dataset.getColumnAsArray(2);//put 2nd column in array

application.setValueListItems( “stateList”, nameArray , idArray )  
}

---

<div class="post-metadata">

### Author: ![IT2Be](https://avatars.discourse-cdn.com/v4/letter/i/dc4da7/32.png) [@IT2Be](https://forum.servoy.com/u/IT2Be)
#### Post date: [September 16, 2008, 7:35pm UTC](https://forum.servoy.com/t/get-selected-value-from-combobox/9599/2 "2008-09-16T19:35:29Z")

</div>

I have not looked at your code (little impatient tonight) but the id is what should be returned to the field (type combo in your case) and attached dataprovider.  
So, at the onDataChange event you can get the value from the dataprovider.

---

<div class="post-metadata">

### Author: ![ROCLASI](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/roclasi/32/4371_2.png) [@ROCLASI](https://forum.servoy.com/u/ROCLASI)
#### Post date: [September 16, 2008, 8:22pm UTC](https://forum.servoy.com/t/get-selected-value-from-combobox/9599/3 "2008-09-16T20:22:05Z")

</div>

Hi Keith,

You are using, what I call, a 2 column value list. This means it contains a display value (column 1) and a real value (column 2).  
You see and select the display value but the real value (the ID in this case) gets stored in the dataprovider that has this combobox.  
So if your dataprovider is already that global variable you want to set then you are already done.  
Or else you can do, like Marcel already suggested, use an onDataChange event on that field to set the variable you want with the stored ID.

Hope this helps.

---

<div class="post-metadata">

### Author: ![kschuster](https://avatars.discourse-cdn.com/v4/letter/k/9d8465/32.png) [@kschuster](https://forum.servoy.com/u/kschuster)
#### Post date: [September 16, 2008, 11:20pm UTC](https://forum.servoy.com/t/get-selected-value-from-combobox/9599/4 "2008-09-16T23:20:26Z")

</div>

Ok I’m close… Sorry… Newbie here…

the OnDataChange. I create a method to set the value of the global variable. What is the code the grab that value

function setStateID()  
{  
globals.stateIdSelected = form.frm\_JursList.elements…???  
}

---

<div class="post-metadata">

### Author: ![ROCLASI](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/roclasi/32/4371_2.png) [@ROCLASI](https://forum.servoy.com/u/ROCLASI)
#### Post date: [September 16, 2008, 11:39pm UTC](https://forum.servoy.com/t/get-selected-value-from-combobox/9599/5 "2008-09-16T23:39:48Z")

</div>

Hi Keith,

No need to address the field on the form, just address it’s dataprovider like so:

```auto
function setStateID()
{
   globals.stateIdSelected = form.frm_JursList.columnName;
}

```

---

<div class="post-metadata">

### Author: ![kschuster](https://avatars.discourse-cdn.com/v4/letter/k/9d8465/32.png) [@kschuster](https://forum.servoy.com/u/kschuster)
#### Post date: [September 17, 2008, 7:06am UTC](https://forum.servoy.com/t/get-selected-value-from-combobox/9599/6 "2008-09-17T07:06:06Z")

</div>

Ok I used this to create the valuelist for the combobox which is fired on form load

function refreshStateList()  
{  
var maxReturedRows = 60;  
var query = ‘select stateName, StateID from tbl\_states’;  
var dataset = databaseManager.getDataSetByQuery(controller.getServerName(), query, null, maxReturedRows);  
var nameArray = dataset.getColumnAsArray(1);//put 1st column in array  
var idArray = dataset.getColumnAsArray(2);//put 2nd column in array  
application.setValueListItems( “stateList”, nameArray , idArray )  
}

Combobox name = cb\_selectState  
In an attempt to “see” the values selected I used this  
function showValueList()  
{  
plugins.dialogs.showInfoDialog( ‘test’,forms.frm\_JursList.elements.cb\_selectState , ‘OK’)  
}

This produced a popup  
DataComboBox[cb\_selectState:null:60]

60 IS the id I want to assigned to globals.stateIdSelected

Given this - how do I set the variable to 60?

---

<div class="post-metadata">

### Author: ![ROCLASI](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/roclasi/32/4371_2.png) [@ROCLASI](https://forum.servoy.com/u/ROCLASI)
#### Post date: [September 17, 2008, 7:27am UTC](https://forum.servoy.com/t/get-selected-value-from-combobox/9599/7 "2008-09-17T07:27:39Z")

</div>

Hi Keith,

You do need to add a dataprovider to that field. Right now it’s null.  
Just add the globals.stateIdSelected as dataprovider and you can loose the whole onDataChange method altogether.

---

<div class="post-metadata">

### Author: ![IT2Be](https://avatars.discourse-cdn.com/v4/letter/i/dc4da7/32.png) [@IT2Be](https://forum.servoy.com/u/IT2Be)
#### Post date: [September 17, 2008, 7:31am UTC](https://forum.servoy.com/t/get-selected-value-from-combobox/9599/8 "2008-09-17T07:31:13Z")

</div>

I am not sure what/why you do it like this but I have the idea you make your life much more difficult than necessary.

You can define the valuelist so that it is generated automatically for you.  
You can hook up the list to the combobox without scripting.  
You can attach the global var to that combobox  
When you do so the selected value will automatically end up in that global var.

Maybe it is me but I miss the point about your dialog…

---

<div class="post-metadata">

### Author: ![kschuster](https://avatars.discourse-cdn.com/v4/letter/k/9d8465/32.png) [@kschuster](https://forum.servoy.com/u/kschuster)
#### Post date: [September 17, 2008, 2:12pm UTC](https://forum.servoy.com/t/get-selected-value-from-combobox/9599/9 "2008-09-17T14:12:09Z")

</div>

Ok I’m working through you method. I was working with the script to load values to the valuelist because it was updating my data in the underlying table. I found ‘editable’…

---

<div class="post-metadata">

### Author: ![ROCLASI](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/roclasi/32/4371_2.png) [@ROCLASI](https://forum.servoy.com/u/ROCLASI)
#### Post date: [September 18, 2008, 6:26am UTC](https://forum.servoy.com/t/get-selected-value-from-combobox/9599/10 "2008-09-18T06:26:35Z")

</div>

Hi Keith,

Did you link your formfield to a dataprovider yet? You _need_ to link it to a global variable or a table column.

---

<div class="post-metadata">

### Author: ![mike65](https://avatars.discourse-cdn.com/v4/letter/m/bc79bd/32.png) [@mike65](https://forum.servoy.com/u/mike65)
#### Post date: [December 5, 2008, 11:06am UTC](https://forum.servoy.com/t/get-selected-value-from-combobox/9599/11 "2008-12-05T11:06:44Z")

</div>

They are forced to move my first solution in Servoy4.1. ![:D]( "Very Happy") ![:(]( "Sad")  
Because in Servoy 3.5.7 three combobox do not work in the same line in tableview. After weeks of hard job I have found three combobox they work alone on new release the 4.1.  
Example, when mouse to go on other line :  
-First combobox name-category, id-category, choose new category item= all right!  
-Second combobox name-family, id-family, choose new family item= KO! If category is different, Servoy insert previously line selected combobox **name** family.  
-Third combobox name-item, id-item, choose new item= KO! If family is different, Servoy insert previously line selected combobox **name** item.  
In both cases, Servoy “feels” that it is changed the field and run the method onDataChange!  
To go to Servoy 4.x !!!  
Windows XP  
Java 11.0  
Servoy 3.5.7
