一旦提交表单,回声选择=“已选择”

时间:2013-09-09 13:38:41

标签: php forms echo

我需要在表单提交后回显 selected =“selected”

echo '<form id="myform1" class="myform1" method="GET" name="myform1">';
echo '<select id="SortBy" name="SortBy" onchange="return submitForm1()">';
echo '<option value="" disabled="disabled">Order By</option>';
echo '<option value="RegularPrice">Price</option>';// if selected echo selected="selected"
echo '<option value="MaxGuests">Max Guests</option>';// if selected echo selected="selected"
echo '</select>';
echo '</form>';

任何想法?

1 个答案:

答案 0 :(得分:0)

<?php

  echo '<option value="RegularPrice"';
  if (isset($_GET['SortBy']) AND $_GET['SortBy'] == 'RegularPrice') {
    echo ' selected="selected"';
  }
  echo '>Price</option>';

?>