Jump to content

[SOLVED] Select box - PHP Result Question?


Solarpitch

Recommended Posts

Hi,

 

I'm trying to make a selection in a Option Box based on a value of a variable. I have the variable $category that will store that value of a Manufacturer. So if it value is "Titleist", I want the option box to have that value selected

 

<select name="select" style="width:254px; ">

  <option value="Callaway">Callaway</option>
  <option value="Ping" >Ping</option>
          <option value="Titleist" SELECTED>Ping</option>
          <option value="Cobra" >Ping</option>

      </select> 

Link to comment
https://forums.phpfreaks.com/topic/113872-solved-select-box-php-result-question/
Share on other sites

If your selected value is going to vary then you can use a variable and do it

 

for eg.

$var = 'pqr1';

 

if($var == 'pqr1'){

  $selected = 'SELECTED';

}else{

  $selected = '';

}

<select name="abc" />

<option value="pqr" $selected> pqr </option>

<option value="pqr1" $selected> pqr1 </option>

<option value="pqr2" $selected> pqr2 </option>

</select>

 

this way you wouldn't have to have multiple if's and else's

I hope this helps

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.