- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-11-2019 11:14 PM
Lets take an example like I hav 3 fields like country,state,city
If country is selected as india,then the other two field choices should show only India states in State field and cities in City field. I have done something in client script but still notihg is changing.
Please let me know where I went wrong
heres the code I have tried it for country and state fields;
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var a=g_form.getValue('u_country');
if(a=='India')
{
g_form.addOption('u_statte','ap','Ap');
g_form.addOption('u_statte','karnataka','Karnataka');
g_form.removeOption('u_statte','california','California');
g_form.removeOption('u_statte','washington','Washington');
g_form.removeOption('u_statte','victoria','Victoria');
g_form.removeOption('u_statte','south aus','South Aus');
}
}
Thanks in Advance!
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-11-2019 11:23 PM
Hi,
Technically for such things you can use dependent field but this works only when the choices are NOT static.
Your client script looks fine.
Also, since you have written onchange on country field, you can directly access newValue variable which will give the latest selection of the country field.
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
//var a=g_form.getValue('u_country');
g_form.addInfoMessage("Value is "+newValue);
if(newValue=='India')
{
g_form.addInfoMessage("Entered into if condition");
g_form.addOption('u_statte','ap','Ap');
g_form.addOption('u_statte','karnataka','Karnataka');
g_form.removeOption('u_statte','california','California');
g_form.removeOption('u_statte','washington','Washington');
g_form.removeOption('u_statte','victoria','Victoria');
g_form.removeOption('u_statte','south aus','South Aus');
}
}
Also verify if the field name u_statte is correct or not.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-11-2019 11:47 PM
So what is the length that you are getting?
And did you write this onChange function on country field?
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
g_form.addInfoMessage("Value is "+newValue+"--"+newValue.length);
if(newValue=='India')
{
g_form.addInfoMessage("Entered into if condition");
g_form.addOption('u_statte','ap','Ap');
g_form.addOption('u_statte','karnataka','Karnataka');
g_form.removeOption('u_statte','california','California');
g_form.removeOption('u_statte','washington','Washington');
g_form.removeOption('u_statte','victoria','Victoria');
g_form.removeOption('u_statte','south aus','South Aus');
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-11-2019 11:54 PM
I am getting the value as 5 and yes it is on country field! but still its not passing into if condition

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-11-2019 11:58 PM
Make it === and check.
And when you say its not working, what are the values in state field being shown?
And can you share the latest code that you have here.
Also open your browser console and check once if you are seeing any error?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-11-2019 11:59 PM
Also, just try with info message and nothing else.
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
g_form.addInfoMessage("Value is "+newValue+"--"+newValue.length);
if(newValue=="India")
{
g_form.addInfoMessage("Entered into if condition");
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-12-2019 12:07 AM
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
//var a=g_form.getValue('u_country');
//g_form.addInfoMessage("Value is "+a);
g_form.addInfoMessage("Value is "+newValue+"--"+newValue.length);
if(newValue === 'India')
{
g_form.addInfoMessage("Entered into if condition");
g_form.addOption('u_statte','Ap','ap');
g_form.addOption('u_statte','Karnataka','karnataka');
g_form.removeOption('u_statte','california','California');
g_form.removeOption('u_statte','washington','Washington');
g_form.removeOption('u_statte','victoria','Victoria');
g_form.removeOption('u_statte','south aus','South Aus');
}
}
I have tried it but no its not working