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>

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>

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.