0

cna anyone tell me how to use the Select = "selected" option for a simple dropdown. for example when someone chooses c it will have a code like <option selected="">c</option> (am I doing it right, well if you got a firebug some site with dropdowns offers that option) so can anyone tell me how that works. I will be using it for a purpose of just selecting parts on my array, well incorporating it... so yah, thanks guys

<html>
<body>

<select>
  <option>a</option>
  <option>b</option>
  <option>c</option>
  <option>d</option>
</select>
 
</body>
</html>
2
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by ekseks
0

Below is php code example.
If $value is 'c' then it will remain selected ..
same for 'a','c','d'.

<html>
<body>
<?
	$value = 'c';
?>
<select>
  <option <?=($value == 'a')?'selected="selected"':''?> >a</option>
  <option <?=($value == 'b')?'selected="selected"':''?> >b</option>
  <option <?=($value == 'c')?'selected="selected"':''?> >c</option>
  <option <?=($value == 'd')?'selected="selected"':''?> >d</option>
</select>
 
</body>
</html>
0

Hi vibhadevit,

I'm new to PHP and I know this is a simpe PHP program but how does this work? Well, I wanted to place that selected part

'selected="selected"'

to what element I will choose in my select list

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.