If 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
Announcements
If 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
Hi @Anonymous ,
when i do this kind of things in projects, i need two things:
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 🙂 )
Lucas001
60
Super User 2025 Season 1
Fubar
55
Super User 2025 Season 1
surya narayanan
35