getValue() is returning label of a choice instead of Value

Yesh
Tera Contributor

Hi all,

I want to get the value of a choice of a field. 

Field Label: Month

Field ID: month

Field Type: Choice

var month = g_form.getValue('month');
g_form.addInfoMessage(month);

By this I am getting the 'January', but I need the value of January i.e., '1'.

How to achieve this?

Thanks,

Yesh

16 REPLIES 16

Chetan Mahajan
Kilo Sage
Kilo Sage

Hi Yesh,

                     is your backend value is 1 for January in choice ?

Hi Chetan,

Yes, The backend Value of January is 1 in choice.

Hi Yesh, 

              Not sure but can you please try below one

var choiceValue = g_form.getValue(<fieldName>); 
var choice = g_form.getOption(<fieldName>, choiceValue).value;

Hi Chetan,

The script you have given not returning any value. It is returning ([object HTMLOptionElement]) this in info message.

Regards,

Yesh