Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I want a checkbox to be checked by default, [duplicate]

Tags:

php

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>
like image 212
Omar Faruk Avatar asked Mar 11 '23 04:03

Omar Faruk


2 Answers

You can use the selected attribute.

<select name="semester">
     <option value="">Select Semester</option>
     <option value="1" selected="selected">Semester 1</option>
     <option value="2">Semester 2</option>
     <option value="3">Semester 3</option>
</select>
like image 111
Ben Hillier Avatar answered Mar 17 '23 11:03

Ben Hillier


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>
like image 39
Sumon Hasan Avatar answered Mar 17 '23 13:03

Sumon Hasan