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

  • SEARCH
  • Home
  • 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 7698945
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T22:21:44+00:00 2026-05-31T22:21:44+00:00

How do we update a textbox on ticking checkboxes? Please see the following code,

  • 0

How do we update a textbox on ticking checkboxes? Please see the following code, only ‘School’ gets filled on clicking the checkboxes. I would like to fill all the three words on ticking.

<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
function updatebox()
{
    var textbox = document.getElementById("list")
    textbox.value =  ""

    if(document.getElementById('cb2').checked) {
        textbox.value = "School"
    }

    if(document.getElementById('cb3').checked) {
            textbox.value =  textbox.value + " College "
        }

    if(document.getElementById('cb4').checked) {
            textbox.value =  textbox.value + " University"
        }
}
</script>
</head>
<body>
<input id="cb2" type="checkbox" name="vehicle" value="School" onclick="updatebox()" /> School <br />
<input id="cb3 "type="checkbox" name="vehicle" value="College" onclick="updatebox()" /> College<br />
<input id="cb4" type="checkbox" name="vehicle" value="University" onclick="updatebox()" /> University<br />
<input id="list" type="text" name="list" />

</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-05-31T22:21:45+00:00Added an answer on May 31, 2026 at 10:21 pm

    Your script is throwing an error because you don’t have a checkbox called "cb3" (because of a typo in your HTML, it’s either called "cb3 " — with the space at the end — or it doesn’t have an ID at all [as spaces are not valid in IDs], depending on the browser). Without the typo, it mostly works as you intended although if School isn’t checked, you get a space at the beginning and if University isn’t checked but College is, you get a space at the end.


    Side note #1: Your code is relying on the horror that is Automatic Semicolon Insertion. I strongly recommend not relying on it. Always include all required semicolons.

    Side note #2: There are lots of ways to avoid having the space if “School” isn’t ticked. One of the easiest is just to use an array and Array#join with space as the separator, like this (I’ve also added the semicolons):

    function updatebox()
    {
        var textbox = document.getElementById("list");
        var values = [];
    
        if(document.getElementById('cb2').checked) {
            values.push("School");
        }
    
        if(document.getElementById('cb3').checked) {
            values.push("College");
        }
    
        if(document.getElementById('cb4').checked) {
            values.push("University");
        }
    
        textbox.value = values.join(" ");
    }
    

    Live example | source

    Side note #3: label elements can make checkboxes much easier to use by allowing clicking on the label as well as the actual box:

    <label><input id="cb2" type="checkbox" name="vehicle" value="School" onclick="updatebox()" /> School</label><br />
    <label><input id="cb3" type="checkbox" name="vehicle" value="College" onclick="updatebox()" /> College</label><br />
    <label><input id="cb4" type="checkbox" name="vehicle" value="University" onclick="updatebox()" /> University</label><br />
    <input id="list" type="text" name="list" />
    

    Live example | source

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to update a form's textbox in winforms with data that is
I have an if statement that needs to look like this: UPDATE $(input#textbox).keypress(function(e){ key==e.which;
Update: Solved, with code I got it working, see my answer below for the
I can't get my textbox to update the database. The changes look like they
In vb6 you could see a textbox update immediately when the value was changed,
UPDATE : The full site code is here - https://github.com/eWizardII/PeerInstruction I have the following
I have update panel that content check box, textbox, 3 DropDownList with CascadingDropDown extender.
I have a textbox bound to a property. The property continously gets updated from
UPDATE: Focus your answers on hardware solutions please. What hardware/tools/add-in are you using to
Update : Looks like the query does not throw any timeout. The connection is

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.