Afnan Ahmad
Afnan Ahmad

Reputation: 2542

what is the function of attribute selected in combo box while fetching data from MYSQL in php

Hello i am beginner in PHP. I am trying to fetch data from MYSQL and want to show in combo box but if user does not re selects the item from item list it highlights error that nothing is selected. Is there any php function to do this particular task ? I want that when the data of particular id is loaded in form and if without making any change in combo boxes data user cliks on submit then it must submit but in my case it shows that the fields are empty while data is here. Here is my Code

<li id="foli3" class="notranslate      ">
<label class="desc" id="title3" for="Field3">
what is the current occupation of your guardian?
<span id="req_3" class="req">*</span>
</label>
<span>
    <select id="Field3" name="occupation" class="field select addr" tabindex="8" required >

        <option value="" selected="selected"><?php echo $rows['occupation']; ?></option>
                        <option>Private Sector Employee</option>
                        <option>Social Sector Employee</option>
                        <option>Agriculturalist</option>
                        <option>Businessman</option>
                        <option>Government Employee</option>
                        <option>Other</option>
    </select>
</span>
</li>

Upvotes: 0

Views: 433

Answers (2)

kwelsan
kwelsan

Reputation: 1219

Try to use option with value attribute:

e.g.

<option value="Private Sector Employee">Private Sector Employee</option>
<option value="Social Sector Employee">Social Sector Employee</option

Upvotes: 0

user1670866
user1670866

Reputation: 68

use jQuery to select default value for combo box.

<select id="mySelect">
<option value="foo">Foo</option>
<option value="bar">Bar</option>
<option value="quux">Quux</option>
</select>

$("#mySelect").val("quux");

Upvotes: 0

Related Questions