Hassaan Mahmood
Hassaan Mahmood

Reputation: 3

Array Search and Checkboxes

i cant seem to make the checkbox appear as checked if this statement turns out to be true. the array passed is working fine and everything is in palce but i dont seem to find a way where i can make the checkbox checked if the value of BSS is there

      <?php if(isset($_GET['cng']) && array_search("BSS", $scharr))
      {
        echo "checked=''";
      };

      ?>/>
      BSS
      </label>

Upvotes: 0

Views: 75

Answers (3)

MahdiY
MahdiY

Reputation: 1306

try below code:

<label for="one"> 
<input type="checkbox" name="school[]" value="BSS" <?php echo isset( $_GET['cng'] ) && in_array("BSS", $scharr) ? 'checked' : ''; }; ?> /> 
BSS </label>

Upvotes: 1

Reshma
Reshma

Reputation: 34

Try this code

<input type="checkbox" <?php if(isset($_GET['cng']) && array_search("BSS", $scharr)) { echo "checked";}>

Upvotes: 0

Saeed M.
Saeed M.

Reputation: 2361

<input type="checkbox" <?php if(isset($_GET['cng']) && isset($scharr['BSS'])) echo "checked"?> />

Upvotes: 0

Related Questions