I have dropdown list of almost all contries and I want to show ‘Singapore’ as default selected country in dropdown list
I have created the list like below
<select name="country" id = "country">
<option value="">Select One</option>
<?php foreach($all_countries as $scountry) {?>
<option value="<?php echo $scountry->country_id;?>"> <?php echo $scountry->country_name;?></option>
<?php } ?>
</select>
But I am unable to select Singapore as default country , how should I do it , please guide me ?
selected
(Though if you’re going to select one of the options as the default, don’t include a “Select One” option.)
but the singapore is not at first place (its in alphabetical order in list)
I suggest you click on the link above and read it.
2 Likes
Hi there xcfx2888,
does this help…
<select name="country" id = "country">
<option value="">Select One</option>
<?php foreach($all_countries as $scountry) {?>
<option value="<?php echo $scountry->country_id;?>"<?php if($scountry->country_name=='Singapore'){echo ' selected';}?>><?php echo $scountry->country_name;?></option>
<?php }?>
</select>
coothead
2 Likes
system
Closed
September 19, 2019, 5:44pm
6
This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.