Automatic create data field

Automatic create data field

Hello,

I got this problem:

Product:  apple,  tomato,  banana,  caret, 
Code:         1    ,      2     ,    3     ,   4    ,


The Case:
When user select on drop down filed " Apple" the form will create automatically the code on a single line filed named Code.

For example:

input - select > Apple
output - Automatically get > 1

input - select > Tomato
output - Automatically get > 2

What is the best way to do it with big database? 

Looking forward for your answer.

Itai B.