The CreatorCon Call for Content is officially open! Get started here.

Based on state country name should be autopopulated

Pravallika9
Tera Expert

Hi,

I have a field "state" choice field contains multiple choice.

Now country field which is a string field.

Based on state field selected I want country to be autopopulated.

 the logic what I want to implement is :

the choices which are there in state are fixed choices.

So I am dividing them like if choices are karnataka, texas

var state = g_form.getValue('u_state');
	if(state == "karnataka"){
g_form.setValue('country') == India;}
else if(state == "Texas"){
g_form.setValue('country') == USA;}
		
	

 

 but it works only on client side, I want to implement the same on server side as well.

how to achieve

6 REPLIES 6

Hitoshi Ozawa
Giga Sage
Giga Sage

Or without creating any Client Script nor Script Include.

I've set both State and Country fields to be of type Lookup Select Box.

1. State field

find_real_file.png

2. Country field

Check "Unique values only" field.

Set Reference qualifier

javascript: 'state=' + current.variables.state; 

Set Variable attributes

ref_qual_elements=country;state

find_real_file.png

Execution result

find_real_file.png

Hitoshi Ozawa
Giga Sage
Giga Sage

After all these, if still want to use if-else statement,

var LocationUtil = Class.create();
LocationUtil.prototype = {
    initialize: function() {},
    getCountry: function(state) {
		var country;
        if (state == "karnataka") {
            country = 'India';
        } else if (state == "Texas") {
            country = 'USA';
        }
		return country;
    },
    type: 'LocationUtil'
};

Sample server script

var state = 'Texas';
var country = new LocationUtil().getCountry(state);
gs.info(country);

Result

*** Script: USA