开发者

Show the option of the drop down list that is equal on the variable on the url

开发者 https://www.devze.com 2023-03-03 20:46 出处:网络
I have the following drop down list. How c开发者_运维知识库an I show the correct option based on the url e.g. www.domain.com/?car=Algema&city=Paris

I have the following drop down list. How c开发者_运维知识库an I show the correct option based on the url e.g. www.domain.com/?car=Algema&city=Paris

What I did is add a value="echo $_REQUEST['car'];" because I used the same on my textboxes but it is not working.

I am using PHP.

<select name="car" value="echo $_REQUEST['car'];" id="car" class="select">
<option value="Algema">Algema</option>
<option value="Barkas">Barkas</option>
<option value="Cadillac">Cadillac</option>
</select>


<select name="car" id="car" class="select">
<option value="Algema" <?php echo $_REQUEST['car'] == 'Algema' ? 'selected="selected"' : '';?>>Algema</option>
<option value="Barkas" <?php echo $_REQUEST['car'] == 'Barkas' ? 'selected="selected"' : '';?>>Barkas</option>
<option value="Cadillac" <?php echo $_REQUEST['car'] == 'Cadillac' ? 'selected="selected"' : '';?>>Cadillac</option>
</select>


I can't answer with PHP specific code but you need to set the selected attribute of the option you would like to select to selected.


<select name="car" id="car" class="select">
  <option value="Algema" <?=($_GET['car'] == 'Algema') ? 'selected="selected"' : NULL?>>Algema</option>
  <option value="Barkas" <?=($_GET['car'] == 'Barkas') ? 'selected="selected"' : NULL?>>Barkas</option>
  <option value="Cadillac" <?=($_GET['car'] == 'Cadillac') ? 'selected="selected"' : NULL?>>Cadillac</option>
</select>
0

精彩评论

暂无评论...
验证码 换一张
取 消