Topic: display value double drop downlist

Hello,

I have a question regarding double dropdownlist. I have no problem in order to  insert and save the data. the problem comes when on the update page, I would like to display again the value of the selected item, there is double value in the dropdown list. How to remove the double item in the drop down list ya?



Appreciate your prompt response on this matter as i need to submit my project as soon as possible.



Unit
--------

<select name="unit" size="1" onChange="redirect(this.options.selectedIndex)" >
      <option  selected> <?= $row['unit']?></option>
     <option value="Unit 1">Unit 1</option>
      <option value="Unit 2">Unit 2</option>
      <option value="Unit 3">Unit 3</option>
      <option value="Unit 4">Unit 4</option>
      <option value="Unit 5">Unit 5</option>
      <option value="Unit 6">Unit 6</option>
      <option value="Unit 7">Unit 7</option>
      <option value="Unit 8" >Unit 8</option>
      </option>
      
      
</select>

Officer
---------

 <td >Officer in Charge: </td>
    <td>      <select name="officer" size="1">
        <option selected>
        <?=$row['officer']?>
        </option>
        <option onClick="this.options.selectedIndex"></option>
      </select></td>

Vote up Vote down

Re: display value double drop downlist

Hello everyone,

i hope that somebody expert from this forum  can help me solve this problem..

Thank you very much smile

Vote up Vote down

Re: display value double drop downlist

To be honest, I'm not completely sure I understand what you are trying to do.

If you are trying to set the dropdown so that the selected value is correct, here is what I have done in the past:

<select name="options">
<option value="">Please select</option>
<option value="option1" <?php if(isset($data) && $data=="option1") echo "selected='selected'" ?>>Option 1</option>
<option value="option2" <?php if(isset($data) && $data=="option2") echo "selected='selected'" ?>>Option 2</option>
<option value="option3" <?php if(isset($data) && $data=="option3") echo "selected='selected'" ?>>Option 3</option>
</select>

This assumes that I've set a PHP variable named "data" to hold the selected value. When I create the <select>, I check if the $data variable is set (this makes sure that the dropdown should hold a value, if it is blank, none of the dropdown items are selected) and then check if the $data value is equal to the option's value. If so, I echo out "selected='selected'" which makes that item selected.

Make sense?

Benjamin Falk | Falken Creative : Twitter
Skills: Photoshop, Illustrator, HTML, CSS, jQuery, PHP and CodeIgniter

Vote up Vote down