Pull-down menu

Hi All,

I have a pull-down menu for a field called subagein with the following items in it:

Mother
Father
Other

What I’m trying to do is when user selects Mother from the Pull-down menu then 0 gets inserted in the subagein, for Father 1 and for Other 2.

I have the following script but somehow the script does not work properly:

var Mother = “Mother”
var Father = “Father”
var Other = “Other”

if(subagein == “Mother”)
{
subagein = “0”

}
if (subagein == “Father”)

{ subagein = “1”}

if (subagein == “Other”)

{ subagein = “2”}

else

{return ;}

is there any other way to do this?

Thanks in advance,

Abrahim

Why don’t you use a value list that shows the items Mother, Father, … and returns the ID?

You can use a manual value list with these entries:

Mother|0
Father|1
Other|2

or use application.setValueListItems(yourvaluelist) to do that by method.

Thanks Patrick,

That was very helpful.

Abrahim

No problem. With your method the following happens: I choose “mother”, your method sets the selection to “0”. “0” is not part of the value list, so Servoy doesn’t display the field value “0”. I (the user) think, I haven’t chosen the value right and choose it again. And again, you set me to “0”. And so forth.

Usually in situations like that, you have your “subageins” in a table. They have a name and an ID in that table (and maybe more). You define a value list that shows you the name and returns the ID (not a custom, but a Servoy value list using database values). The important checkboxes are “show in field/list” and “Return in dataprovider”. And then you’re done. No method, no hassle.

You can use a manual value list with these entries:

Mother|0
Father|1
Other|2

Adding to this: you can also use internationalization in your valuelist!
Your entries can look like this:

i18n:solutionname.label.mother|0
i18n:solutionname.label.father|1
i18n:solutionname.label.other|2

Have fun with it!

Patrick and Karel,

Useful information!

Thanks again for the help.

Abrahim