FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!

Having a check box true or false possible?




AS in ...

Code:
<!DOCTYPE html>
<html>
<body>

<form action="demo_form.php" method="get">
  <input type="checkbox" name="online" value="onlinestream" checked> I am online<br>
  <input type="submit" value="Submit">
</form>

</body>
</html>


If the box is checked and they are online then display this image, if they don't have it checked then display this other image...

Is that possible??



1 blog comments below

Of course this is possible:

Code:

<html>
<body>
<form action="demo_form.php" method="get">
    <input type="checkbox" id="checkbox" name="online" value="onlinestream" onclick="handle_checkbox();" checked > I am online<br>
</form>
<div id="logon_img"></div>
<script>
    function handle_checkbox() {
        if (document.getElementById("checkbox").checked) {
            document.getElementById("logon_img").innerHTML = "<img src=\"https://blogvault.net/wp-content/uploads/2014/10/Login.jpg\">";
        } else {
            document.getElementById("logon_img").innerHTML = "<img src=\"http://store.3abn.org/merchant2/graphics/00000001/LoginRed.jpg\">";
        }
    }
</script>
</body>
</html>


You don't even need that submit button when using a checkbox.
See my jsfiddle here: http://jsfiddle.net/amagard/p5do09ax/
However as a user I would prefer a login button with turns into a logoff button once I am logged in. Using a check box is not intuitive or common for this user case.
amagard on Sun Feb 08, 2015 3:48 pm



FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.