0

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
Contributors
5
Replies
34
Views
4 Years
Discussion Span
Last Post by B0716L
0

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...

0

In PHP,you can do like this:

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

Edited by pritaeas: Added markdown.

2

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" />
Votes + Comments
best advice i've heard
0

@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.