Muiter
Muiter

Reputation: 1520

Echo selected in drop down menu

I am getting confused now. Why am I not able to echo an selected item?

                  echo'
                  <form class="form-horizontal form-calculator" id="interval" action="includes/toolbox_interval.php" method="post">
                  <div class="modal-body">
                      <div class="form-group">
                          <label for="interval">Kies interval</label>
                          <select class="form-control" name="interval" id="interval">
                            <option></option>
                            <option'; if($row['days'] == 7){ echo 'selected="selected"'; } echo 'value="7">Wekelijks</option>
                            <option value="14">2 wekelijks</option>
                            <option value="30">Maandelijks</option>
                            <option value="91">Elk kwartaal</option>
                            <option value="365">Jaarlijks</option>
                          </select>
                        </div>
                  </div>
                  </form>';

Upvotes: 0

Views: 185

Answers (1)

Rushikumar
Rushikumar

Reputation: 1812

Muiter,

For one, you need spaces, try the following--

<option '; if($row['days'] == 7){ echo 'selected="selected"'; } echo ' value="7">Wekelijks</option>

Notice the space after option tag and before the value attribute

If you do not have the spaces, here are the scenarios you are facing...

  1. The if condition has met. As a result, your resulting option tag will be:

    <optionselected="selected"value="7">Wekelijks</option>
    
  2. The if condition has not met. In which case, your resulting option tag will be:

    <optionvalue="7">Wekelijks</option> 
    

Hope this helps!

-Rush

Upvotes: 1

Related Questions