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 :)

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

<html> 
<--! doctype is whatever you want... -->
<head>
<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;
}
</script>
</head>
<body onload="onload();">
<input type="checkbox" name="whatever" value="1" id="mycheckbox" onclick="setChecked();"/>

</body>
</html>

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'; ?>>
Member Avatar for stbuchok

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

here:

<input type="checkbox" checked disabled="disabled" />
commented: best advice i've heard +14

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.