How To Populate A State List With Country Dropdown In Pega

Posted on
  1. State List Of India
  2. State List Abbreviation
  3. How To Populate A State List With Country Dropdown In Pega C
  • Thanks, that's the way I was thinking of doing it. I've done it in a text, value class, that creates a new razor select list item for each country.
  • I have the code below that will change a state dropdown list when you change the country list. How can I make it change the state list ONLY when country ID number 234 and 224 are selected?

In the Country entity, use the default Name field to capture the country name. In the parent entity, create new lookup field (E.G: 'Country Name') to the custom 'Country' entity. Now you have the country list in 'Country' entity. You will have the country list in the Lookup field in the parent entity.

Author: IshanDemon
Views Total: 0 Views
Official Page: Go to Website
Last Update: April 25, 2019 at 3:44 am
License: MIT

Preview:

Description:

This Javascript library helps you to create a country & state dropdown lists which contain the names of all country and state names. You can easily implement a country-state without storing in database.

It’s very simple to add the pre-defined class name and attribute into the dropdown select input box field to make it work.

When a user selects a country, The state dropdown will automatically populate according to the selection of the country name.

How to populate a state list with country dropdown in pega c

Create a Country State Dropdown by using JavaScript

It’s dead simple to add it on your website. You can add it on any kind of website. Whether you have a CMS based site or a static website.

The plugin comes with a single countries.js Javascript file. It contains the country and state by using the variable. Moreover, It included some basic functionality to handle the functionality of populating the values.

Let’s load a Javascript file and add in the before closing the head or before closing body tag at end of the page.

Next, Create the list of for country and state. For this, Simply define the select element (without adding option) and add a unique ID for both country & state.

You can add a label if you want. We did add it for demo purpose.

Lastly, We need to initialize the Javascript function. All we need to define the first parameter is the ID of country drop-down and the second parameter is the ID of state drop-down.

Advantages:

By using this plugin, You have a few advantages:

  • No need to save values in the database.
  • No need to use Jquery to avoid conflict.
  • You can manually add/delete and update countries and states.
One easy example to understand the requirement is linkage between Country , State and City. We will have three tables, one is country table storing country name and country code. Second one is State table storing state name and state_id ( unique id of each state ) and country code saying which country this state is belong. Same way we have third table showing city name and city id along with state id to link State name to City. You can download the script at end of this page.

Table Structures

There are three tables to store Country, State and City records.
plus2_state
state_id
state
country_code

This script has one main page to display three dropdown list with a button to submit the form to another page. User can select a country first, then select a state and then select City. After selecting country the available state in the selected country will be displayed as options in the second dropdown list. Same way after selection of state the available cities of the state will be displayed as options for the user to select.

State List Of India

After selection of all three list boxes, the submit button will be enabled to submit the form.

How the script works.

This script works by using PHP script at backend and using JQuery for various control at client side. Records are kept in database table.

Populating Country listbox

We will first populate the country list while loading the page. This part is PHP script only and it populates the list by taking records from database table.

Populating state list

Once one country is selected by user , it will trigger change function of drop down box. Inside the change function we will first remove the available options. We will ensure that submit button is disabled as we have not selected city option yet.
Then we will pass the country_code value of the selection to backend script dropdown3ck.php using POST method. This backend script will use the country_code to get matching state name and state_id from 2nd table ( plus2_state). The list of state_id and state name will be returned through JSON string. Above code will add options to state list based on the selection of country by user. After this once the user select a state, the process starts again by triggering on change event of state dropdown list.

Populating City list

Once the user select a state the onchange event associated with state dropdown list triggers. In the above code we have passed state_id to backend PHP script dropdown3ck.php and collected the list of cities from the table plus2_city.

Selection of City

Once the user select a city , we enable the submit button to Submit the form data to next page. We can modify above lines and add auto submit of form on selection of third drop down list box. Change in code is here. You can remove the button if required.

Selecting one options by default or on page load

We may think on keeping one country selected by default or while loading of the page. User then can change the selection to any other country. To trigger the change event to show state options for Canada in second dropdown we have to trigger the change event of first dropdown list. You can receive the country name from address bar and then keep that country as selected from the first list. Click the country names from the list below. Inside PHP script we can collect the country code from query string and set the hidden html tag with the country code value. Collected country code from query string ( address bar ) Above line should go inside the form

State List Abbreviation

Displaying more details after 3rd drop down is selected.

How To Populate A State List With Country Dropdown In Pega C

You can collect city_id after selection of 3rd list box. Using this ID you can collect data from another table and show to the users. It is explained here how to populate three dropdown list by interlinking them, however adding or deleting options to these drop down list boxes is also part of the site admin function. We can add county or State or City to the table by using the same interlinking. This part is explained in next section.