JSFiddle - React, Tailwind, and code Playground
HTML
<select id="countrycode" name="countrycode">
<option value="INT">International</option>
<option value="USA">USA</option>
<option value="DE">DE</option>
</select>
<div id="us">USA div</div>
<div id="de">DE div</div>
<div id="int">INT div</div>
JavaScript
var selectedCountry = '<? echo $p["country"]; ?>';
//var selectedCountry = 'USA'; // for testing
var divs = $('#us, #de, #int');
var selectedCountry = 'USA';
var countryCodeSelector = $('#countrycode');
countryCodeSelector.val(selectedCountry);
selectCountry(selectedCountry);
countryCodeSelector
.change(
function() {
var code = $(this).val();
selectCountry(code);
}
)
;
function selectCountry(code){
var selectedID = '';
switch(code){
case 'USA':
selectedID = 'us';
break;
case 'DE':
selectedID = 'de';
break;
case 'INT':
selectedID = 'int';
break;
}
divs.hide();
$('#' + selectedID).show();
}