Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to show a drop-down list with a pre-selected option

Tags:

html

php

mysql

I want to update my form when I click edit button then all info is showing correctly but status value is showing all time same open option. I dont know why it is showing same open status and my currently status is done but it is showing all time open please help me to fix this issue thanks

this is my form code username is showing correctly but status is not showing correct

 <p><label class="field" for="username">UserName:</label>
     <input name="username" type="text" id="username"  value="<?php echo $username; ?>" size="50" />
   </p>
  <p>

                <label class="field" for="Status">Status</label>
                    <select name="status" id="status" value="<?php echo $status; ?>"  >
                        <option value="open">Open</option>
                        <option value="done">Done</option>
                        <option value="pending">Pending</option>
                        <option value="working">Working</option>
                    </select>
       </p>
like image 394
msalman Avatar asked Nov 03 '13 07:11

msalman


People also ask

How do you pre select an option in dropdown?

A select box also called drop down box provides an option to list down various options in the form of drop down list. You can also preselect a value in dropdown list of items in HTML forms. For that, add selected in the <option> tag for the value you want to preselect.

How do I populate a drop down list based on another drop down list?

In the same or in another spreadsheet, select a cell or several cells in which you want your primary drop-down list to appear. Go to the Data tab, click Data Validation and set up a drop-down list based on a named range in the usual way by selecting List under Allow and entering the range name in the Source box.

How do I add conditional drop down?

Select the cell where you want the Dependent/Conditional Drop Down list (E3 in this example). Go to Data –> Data Validation. In the Data Validation dialog box, within the setting tab, make sure List in selected. In the Source field, enter the formula =INDIRECT(D3).


1 Answers

Use selected attribute.

<select name="status" id="status">
    <option value="open" <?php if($status=="open") { echo "selected"; } ?> >Open</option>
    <option value="done" <?php if($status=="done") { echo "selected"; } ?> >Done</option>
    <option value="pending" <?php if($status=="pending") { echo "selected"; } ?> >Pending</option>
    <option value="working" <?php if($status=="working") { echo "selected"; } ?> >Working</option>
</select>
like image 110
Sumit Bijvani Avatar answered Sep 21 '22 19:09

Sumit Bijvani