Set php switch as default

I have two switches in my program, but when I run it, none of them are 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

+5
source share
4 answers

Something like that:

<li><input type="radio" name="r1" value="o" onClick="submit();" CHECKED/>On</li>
+7
source

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>
+11
source

How about this:

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

Well, for the On button to be checked, the value $_SESSION['r1']must be equal to "o". Have you checked the value $_SESSION['r1']?

+1
source

All Articles