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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T19:55:10+00:00 2026-06-04T19:55:10+00:00

Im very new to Javascript so any and all input would be welcomed. I

  • 0

Im very new to Javascript so any and all input would be welcomed.
I am having issues in creating a function used to delete selected checkboxes. I have tried numerous things but end up just deleting the entire function.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>Shopping List</title>
        <script>
            /*
            Create a shopping list program using javascript.  The page should have a text input, an “add” button, a “delete checked” button, and a list of items.  Each item should have a checkbox next to it.  If you fill out the text input and click” add,” it should add a list item to the end of the list.  If you check a box (or boxes) next to a list item then click “delete checked,” it should remove the list items that were checked.  Style the page using CSS.  
            */
            function addIt() {
                var list = document.getElementById("list"); //used to grab the parent level "list"
                var li = document.createElement("li"); //creates a "li" in the document
                var userTxt = document.getElementById("product"); //used to grab the user text input "product"
                var childText = userTxt.value; //returns the userTxt value and sets it equal to childText
                var childTextNode = document.createTextNode(childText); //creates a textNode in the document based on what the user entered in the "product" text field
                var chkBox = document.createElement("input"); //creates a new input based on the user input
                chkBox.type = "checkbox"; //creates a checkbox next to the user input from "product"

                //form the relationship
                li.appendChild(chkBox); //
                li.appendChild(childTextNode); //
                //attach to the parent element
                list.appendChild(li); //
                inputText.value = "";
                inputText.focus();
            }
        </script>
    </head>

    <body>
        <div id="content">
            <h1>Shopping Cart</h1>
            <input id="product" type="text" />
            <input type="button" id="Add" value="Add" onclick="addIt()" />
            <input type="button" id="Delete" value="Delete" onclick="deleteIt()" />
            <ul id="list">
                <li>
                    <input type="checkbox" />Eggs</li>
            </ul>
        </div>
        </div>
    </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-04T19:55:13+00:00Added an answer on June 4, 2026 at 7:55 pm

    Input in html (added name tag)

      <ul id="list">
        <li><input type="checkbox" name='food'>Eggs</input></li>
      </ul>
    

    While adding (in addIt() add name to checkbox)

     chkBox.type="checkbox";                                 
    
     chkBox.name = 'food';
    

    Now deleteIt function

    function deleteIt(){
        var food = document.getElementsByName('food'); // get the checkbox
        for (i=0; i<food.length; i++) // loop through it
        {
        // if the current state is checked, unchecked and vice-versa
                if (food[i].checked) // if its checked
                {
                var remElm = food[i];   // element to be removed
            var list=document.getElementById("list"); // also li to be removed           
            food[i].nextSibling.nodeValue = ''; // Text value set to 
            remElm.parentNode.removeChild(remElm);
            ul = document.getElementsByTagName('ul')[0];
            li = ul.getElementsByTagName('li');
            ul.removeChild(li[i]);
                } else {       
                }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm very new to JavaScript in general so having trouble with this. Working with
I am very new at jQuery ... I've used Javascript many times and am
I noticed that JavaScript's new Date() function is very smart in accepting dates in
I'm troubleshooting this code, I am very new to PHP, so any help would
All, I'm pretty new to JavaScript development, so this is probably a very stupid
I am still new at PHP/Javascript/Ajax and am having a very hard time (been
I am very new to javascript, so forgive me for my ignorance. I am
I am new to javascript so sorry I don't know very much. I have
Very new to JQuery and MVC and webdevelopment over all. I'm now trying to
I am very new to jQuery and javascript programming. I have a program below

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.