Auto Select Dynamic Dropdown Matching value of php variable

Auto Select Dynamic Dropdown Matching value of php variable

i want to automatically select value of dropdown matching value of php variable

i want to automatically select value of dropdown matching value of php variable

here is my

    <select class="destinationId" id="destination" name="destinationId" onchange="getNationalityAndLiving(this.value,'','');">
                  <option value="" disabled selected>Select Traveling to</option>
                                <option data-prefix="azerbaijan" value="azerbaijan" >
                  Azerbaijan              </option>
                                <option data-prefix="cambodia" value="cambodia" >
                  Cambodia              </option>
                                <option data-prefix="egypt" value="egypt" >
                  Egypt              </option>
                                <option data-prefix="india" value="india" >
                  India              </option>
                                <option data-prefix="kenya" value="kenya" >
                  Kenya              </option>
                              </select>


<select class="nationality" name="nationality" id="nationality"> <option value="" disabled selected>Select Citizen of</option> </select>

this is my ajax code to retrive dynamic dropdown for select select option "nationality"

    <script>
$(document).ready(function(){

$("#destination").change(function(){
    var deptid = $(this).val();
    var dbnm = "country";
    var res = dbnm.concat(deptid);
    $('.overlay').show();
    $.ajax({
        url: 'getcountry.php',
        type: 'post',
        data: {dest:res},
        dataType: 'json',
        success:function(response){
            var len = response.length;

            $("#nationality").empty();
            for( var i = 0; i&lt;len; i++){
                var id = response[i]['id'];
                var name = response[i]['name'];

                $("#nationality").append("&lt;option data-nation='"+name+"' value='"+name+"'&gt;"+name+"&lt;/option&gt;");

            }
           $('.overlay').hide();            
        }
    });
});

}); </script>

i have some dynamic php variable coming on this page from previous url. for example

$nationality = "some value";

What i want is selected dropdown with value of $nationality in second dropdown,

if it was static i could have achieved this, but how to auto select in dynamic i am not able to get any workaround.

Angular 9 Tutorial: Learn to Build a CRUD Angular App Quickly

What's new in Bootstrap 5 and when Bootstrap 5 release date?

Brave, Chrome, Firefox, Opera or Edge: Which is Better and Faster?

How to Build Progressive Web Apps (PWA) using Angular 9

What is new features in Javascript ES2020 ECMAScript 2020

Autocomplete Textbox with Javascript, PHP and MySQL

In this guide, we will walk through how to add autocomplete to a textbox, with the help of jQuery and also an alternative that works with just vanilla Javascript.

Understand and Use JavaScript's .forEach() vs. jQuery's .each()

There are two functions to deal with an array on the client-side – JavaScript's .forEach() and jQuery's .each(). Here, I will teach you how to use both of these methods with some sample code.

jQuery window on load is firing too early. What else can I use? Javascript in Wordpress

I'm learning jQuery and Javascript, and I'm trying to understand why my code is not working.