tags:

views:

296

answers:

5

Hi , This question asked already but my question is very simple,

in the my accont page, i have the employee country in dropdown,

How to make selected value in combo , when in edit mode,

Thanks

A: 

An option tag will be the default for a select list when the selected attribute is set. In the following code option 2 will show up as the current selected option when the page loads:

<select>
  <option value="1">1</option>
  <option value="2" selected="selected">2</option>
  <option value="3">3</option>
</select>

To achieve this in your PHP code conditionally display the selected attribute on your options against what the current value is:

  <option value="1"<?php if($user['country'] == '1') { ?> selected="selected"<? } ?>>1</option>
  <option value="2"<?php if($user['country'] == '2') { ?> selected="selected"<? } ?>>2</option>
  <option value="3"<?php if($user['country'] == '3') { ?> selected="selected"<? } ?>>3</option>
Cryo
A: 

Let's assume you have the user's country in $user_country and the list of all countries in $all_countries array:

<select id="country">
<?php
foreach ( $all_countries as $country ):
    $selected = "";
    if ( $country == $user_country )
        $selected = "selected";
?>
<option value="<?php echo $country; ?>" 
        selected="<?php echo $selected; ?>">
        <?php echo $country; ?>
</option>
<?php
endforeach; ?>
</select>

should work.

kemp
A: 

Sorry guy/girls ,

For stupid small work i posted the thread,

i got the ans,

Here is my code url,

thanksdropdown select equal to select

Bharanikumar
You can still upvote those who tried to help you
kemp
A: 
Bharanikumar