How to set the selected value or text of choice field

Ankit18
Mega Contributor

Hi,

 

I am using a client script to populate the choice options using below code.

g_form.clearOptions("reason");
g_form.addOption("reason", "", "Please Select One");
for (index = 0; index < newJSOnObject.length; ++index)
{
g_form.addOption("reason", newJSOnObject[index].ReasonCode, newJSOnObject[index].Reason);
}

g_form.setValue("reason", "10");

I need to set the selected value of this choice field and I tried to use g_form.setvalue to set the default selected value of choice option but it did not work.

 

I would appreciate if anyone can help me on this.

Thanks for the help!

 

1 ACCEPTED SOLUTION

Mark Stanger
Giga Sage

That should work as long as you have a string value of "10" as an option for that field.  You might try setting up a client script to output that value (and its type) and see if it all matches.

alert(g_form.getValue("reason") + " : " + typeof(g_form.getValue("reason"));

View solution in original post

3 REPLIES 3

Mark Stanger
Giga Sage

That should work as long as you have a string value of "10" as an option for that field.  You might try setting up a client script to output that value (and its type) and see if it all matches.

alert(g_form.getValue("reason") + " : " + typeof(g_form.getValue("reason"));

Mark Stanger
Giga Sage

Just checking on on this one.  Has this question been answered or is there more information I can help you with?  If it's been answered, please mark the answer above as the correct one so people know this has been taken care of.  Thanks!

Yes Mark, this is helpful. Thank you!