Omar Faruk Omar Faruk - 2 months ago 5
PHP Question

I want a checkbox to be checked by default,

When will I update my semester that time by default a checkbox to be checked how it possible ?

<select name="semester">
<option value="">Select Semester</option>
<option value="1">Semester 1</option>
<option value="2">Semester 2</option>
<option value="3">Semester 3</option>
</select>

Answer

Please try this

<select name="semester">
            <option value="">Select Semester</option>
            <option value="1" <?php if($data['semester']==1){echo 'selected';}?>>Semester 1</option>
            <option value="2" <?php if($data['semester']==2){echo 'selected';}?>>Semester 2</option>
            <option value="3" <?php if($data['semester']==3){echo 'selected';}?>>Semester 3</option>
</select>
Comments