Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Power Pages - Power Apps Portals
Answered

If a value is selected from drop down then a default value should be displayed in other dropdown

(0) ShareShare
ReportReport
Posted on by

Screenshot (20).pngIf in state drop down Uttar Pradesh is selected and it should automatically display its capital as Lucknow in Capital drop down and same for all other states.

i.e default value should be displayed if states are choosen

  • Verified answer
    Christian Leverenz Profile Picture
    1,214 on at
    Re: If a value is selected from drop down then a default value should be displayed in other dropdown

    Hi @Anonymous ,

    when i do this kind of things in projects, i need two things:

    • a list which describes the dependencies (so, what is the capital of a selected state)
    • a changehandler for the stateselector

    As jquery is on portals around, you could do it with jquery.

    The code might look something like this (not tested, just written):

    let mycapitals = [

    { "state" : 1234, "capital" : 3456 }

    ,{ "state" : 5678, "capital" : 78910 }

    ]; // a list of realtion capital to state

     

    let changefunction = (function(src, tgt, rels) {

    var jqtgt = $("#" + tgt); // get the jquery field for the capital

    var jqsrc=$("#" + src); // get the jquery field for the state

    let mychangefun = function() { // create the changefunction

    var srcval = jqsrc.val(); // get the statevalue

    var tgtvalentry = rels.find(e => e.state == srcval); // find the capitalentry

    if(tgtvalentry) { // did we find one?

    jqtgt.val(tgtvalentry.capital); // yes, set the value of the capital

    }

    };

    mychangefun(); // initalize in case of read with the right value

    jqsrc.change(mychangefun); // attach the changefunction to the stateselctor

    return mychangefun; // return back the changefunction of needed to be attached somewhere else

    })("stateselectid","capitalselectid",mycapitals);

     

    just replace stateselectid with your attributename of the state and the capitalselectid with the name of the capitalattribute. May be you have to adjust something, when the capital already has a value.

     

    You can place this code in the entitybasicform or in the template you are using.

    Hope this helps,

      Christian

     

    PS i think, there is only one capital per state. Why should the user select another one? (well, not my challenge 🙂 )

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Paul Stork – Community Spotlight

We are honored to recognize Paul Stork as our July 2025 Community…

Congratulations to the June Top 10 Community Leaders!

These are the community rock stars!

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

Leaderboard > Power Pages

#1
Lucas001 Profile Picture

Lucas001 60 Super User 2025 Season 1

#2
Fubar Profile Picture

Fubar 55 Super User 2025 Season 1

#3
surya narayanan Profile Picture

surya narayanan 35