Does anyone know how to make a checkbox on a web page that always stays checked no matter what computer sees it? It would always stay checked on that exact web page? If anyone knows how to do this, that would be great :)

5 Years
Discussion Span
Last Post by B0716L

I can't see any reason to ever do this... what's the point of a checkbox if you can't interact with it?

However, with js you could just

<--! doctype is whatever you want... -->
<title>Perpetual Checkbox</title>
<script type="text/javascript">
function onload()
    var ChkBx = document.getElementById("mycheckbox");
    ChkBx.checked = true;
function setChecked()
    document.getElementById("mycheckbox").checked = true;
<body onload="onload();">
<input type="checkbox" name="whatever" value="1" id="mycheckbox" onclick="setChecked();"/>


This would perpetually make your checkbox checked... maybe I am misunderstanding you and what you need... but I would think that you want a "hidden" input field, where you can set a "static" value.

<input type="hidden" name="whatever" value="whatever" />

if you want it to persist through page refreshes, you will need a method to "save" the state you are in. You can either append stuff to the URL (but a hard refresh or a direct hit to the root URL will kill that idea), or you can set a cookie, save to a database or storage method of choice...


In PHP,you can do like this:

<input type="checkbox" name="myCheckbox" <?php if ($_REQUEST['myCheckbox']) echo 'checked'; ?>>

Edited by pritaeas: Added markdown.


ok, so you want a checkbox on a page that is always checked and people can't uncheck it?


<input type="checkbox" checked disabled="disabled" />
Votes + Comments
best advice i've heard

@stbuchok That is exactly what I am looking for. Thank you :)

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.