Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8782561
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T20:35:41+00:00 2026-06-13T20:35:41+00:00

I assembled some code that checks the state of a checkbox and then displays

  • 0

I assembled some code that checks the state of a checkbox and then displays the corresponding message as a string. The default state of the checkbox is “unchecked”, but when I reload the page there’s no message displaying “Unchecked”, it will work as intended once I check the checkbox and uncheck. I want the state to display on page load in a nutshell, not on-change. Here’s the code:

<html>
<head>
</head>
<body>

<input type="checkbox" id="checkBox" />
<div id="text"></div>

<script type="text/javascript">
var getId = document.getElementById('text'),
    checkbox = document.getElementById('checkBox');

function checkState(){
    text.innerHTML = checkbox.checked ? "Checkbox is checked" : "Checkbox is empty";
}
checkbox.onchange = checkState;
</script>

</body>
</html>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T20:35:42+00:00Added an answer on June 13, 2026 at 8:35 pm

    You just need to call your own function in addiction to set it as the checkbox onchange event.

    Since you’re executing the script on the end of the body, it only gets executed when you already have access to the DOM, you just need to call checkState() after it’s definition.

    <html>
    <head>
    </head>
    <body>
    
    <input type="checkbox" id="checkBox" />
    <div id="text"></div>
    
    <script type="text/javascript">
    var getId = document.getElementById('text'),
        checkbox = document.getElementById('checkBox');
    
    function checkState(){
        text.innerHTML = checkbox.checked ? "Checkbox is checked" : "Checkbox is empty";
    }
    checkbox.onchange = checkState;
    checkState();
    </script>
    
    </body>
    </html>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need some comments on the code that I assembled. I want to know
I have some C# code that loads an assembly from a certain path like
I have some Javascript code that will programmatically register an COM interop assembly by
I got this piece of Assembly code extracted from some piece of software, but
I decided to modify some code today, and encountered an error that doesn't make
I want to write some C code such that gcc using the -msse4.1 flag
This is my code: public class MyCollection { internal static Dictionary<string, CheckBox> MyCheckBox =
I'm attempting to assemble some 32-bit code using NASM and GCC on a 64-bit
Looking at some assembly code for x86_64 on my Mac, I see the following
Possible Duplicate: Switching to assembly in gdb I am debugging some code in gdb.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.