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 9274761
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T16:25:41+00:00 2026-06-18T16:25:41+00:00

I am trying to work on a form. Currently, the button is disabled. But

  • 0

I am trying to work on a form. Currently, the button is disabled. But when you click on a checkbox, the button should be enable, and then disabled again if you dont have a checkbox clicked on. I cant get the button to become enabled when i click on a checkbox. Probably something wrong with my loop. The loop is in function checkAge. Any solution?

Javascript

function checkAge(e){

var theTarget = e.target ? e.target : e.srcElement;
alert(theTarget.id);

var form = document.getElementById("form");
if (document.getElementById("content")) {
    form.removeChild(document.getElementById("content"));
}

if(theTarget.id == "fourteen"){
    var newDiv = document.createElement("div");
    newDiv.setAttribute("id", "content");

    var br = document.createElement("br");
    newDiv.appendChild(br);
    var br = document.createElement("br");
    newDiv.appendChild(br);

    newDiv.appendChild(document.createTextNode("Vilka seriefigurer träffade du?"));

    var br = document.createElement("br");
    newDiv.appendChild(br);

    var musse = document.createElement('input');
    musse.setAttribute("type", "checkbox");
    musse.setAttribute("name", "musse");
    musse.setAttribute("value", "musse");
    musse.setAttribute("id", "musse");
    newDiv.appendChild(musse);
    newDiv.appendChild(document.createTextNode("Musse"));

    var br = document.createElement("br");
    newDiv.appendChild(br);

    var adi = document.createElement('input');
    adi.setAttribute("type", "checkbox");
    adi.setAttribute("name", "adi");
    adi.setAttribute("value", "adi");
    adi.setAttribute("id", "adi");
    newDiv.appendChild(adi);
    newDiv.appendChild(document.createTextNode("Ådi"));

    var br = document.createElement("br");
    newDiv.appendChild(br);

    var bamse = document.createElement('input');
    bamse.setAttribute("type", "checkbox");
    bamse.setAttribute("name", "bamse");
    bamse.setAttribute("value", "bamse");
    bamse.setAttribute("id", "bamse");
    newDiv.appendChild(bamse);
    newDiv.appendChild(document.createTextNode("Bamse"));

    var br = document.createElement("br");
    newDiv.appendChild(br);

    var input = document.createElement("input");
    input.setAttribute("type", "submit");
    input.setAttribute("name", "submit");
    input.setAttribute("id", "submit");
    input.setAttribute("value", "Skicka");
    newDiv.appendChild(input);

    form.appendChild(newDiv);

    var inputs = document.getElementsByTagName("input");
    for(i=0; i<inputs.length; i++){
        input.disabled = true;
        if(inputs[i].type == "checkbox" && inputs[i].checked){
            input.disabled = false;
        }
        else{
            input.disabled = true;
        }

    }

}
  • 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-18T16:25:42+00:00Added an answer on June 18, 2026 at 4:25 pm

    When you create the checkboxes, you don’t attach any events to them. Your loop to disable the input only happens when you create the checkAge part of the form, and never executes again. If you attach an even to the checkboxes, then it should solve your problem.

    Also, your checkAge function adds the checkbox inputs to the document, but you never update your inputs array to include the checkboxes.

    You may want to consider adding all the HTML elements to the page initially, and using display:none/display:block to hide/show the elements.

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

Sidebar

Related Questions

I'm trying to validate my php form using exception, but somehow it doesn't work.
I'm trying to open a new window form on a button click In main
I'm trying to work this form so when the first radio button is selected,
I'm trying to work with the form dropdown function for the codeigniter form helper.
I am trying to add an ActiveX command button in my work sheet at
I'm trying to use an ajax contact form to send me emails but i'd
I have built a simple registration form shown below and Iam trying to get
I'm trying to insert information from a form into a database table and then
I trying to have a div with child divs that form 2 or more
I am trying to get the click event of a submit button on my

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.