set php radio button checked by default

I have two radio buttons in my program but when i run it none of them is checked, I want one of them to be checked by default,
how can i achieve this ?

<li><input type="radio" name="r1" value="o" onClick="submit();" <?php echo ($_SESSION['r1'] == "o") ? 'checked="checked"' : ''; ?> />On</li>
<li><input type="radio" name="r1" value="p" onClick="submit();" <?php echo ($_SESSION['r1'] == "p") ? 'checked="checked"' : ''; ?> />Off</li>

I want the ‘On’ button to be checked when i open the page for the first time

Related posts

Leave a Reply

4 comments

  1. Here you go:

    <li><input type="radio" name="r1" value="o" onClick="submit();" <?php echo ($_SESSION['r1'] != "p") ? 'checked="checked"' : ''; ?> />On</li>
    <li><input type="radio" name="r1" value="p" onClick="submit();" <?php echo ($_SESSION['r1'] == "p") ? 'checked="checked"' : ''; ?> />Off</li>
    
  2. What about this:

    <li><input type="radio" name="r1" value="o" onClick="submit();" <?php echo (!$_SESSION['r1'] || $_SESSION['r1'] == "o") ? 'checked="checked"' : ''; ?> />On</li