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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T10:49:59+00:00 2026-06-08T10:49:59+00:00

My ‘listmaker’ contains one text box & two buttons. You type an item into

  • 0

My ‘listmaker’ contains one text box & two buttons. You type an item into the text box, hit “Add Item” and the item is pushed to an array. When you’re done, hit finish and a div is populated with a list of your items. Each list item also has a checkbox. I want to remove any list item with a checked checkbox, preferrably by clicking another button to “remove checked items”, but not necessary.

Here’s the html:

<!DOCTYPE html>
<html>
    <head>
        <link rel="stylesheet" href="style.css" />
        <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.1/jquery.min.js"></script>
        <script src='script.js'></script>
        <title>Listmaker</title>
    </head>
    <body>
    <form>
        <input type="text" id="add" />
        <button type="button" name="addItem" id="addItem">Add Item</button>
        <button type="button" name="finish" id="finish">Finish</button> 
        </form>
        <div>
            <ol id="list">
            </ol>
            <button type="button" name="lineThrough" id="lineThrough">Remove Checked Items</button>
        </div>
    </body>
</html>

And the jQuery:

$(document).ready(function() {
        var list = [];
        $('#add').focus();

    $('#addItem').click(function() {
        list.push($('#add').val());
        $('#add').val('');
        $('#add').focus();
    });

    $('#finish').click(function() {
        for(i=0; i<list.length; i++) {
        $('#list').append('<li><input type="checkbox" class="unchecked"/>' +list[i]+ '</li>');
        }
    });

});

I’ve tried it a bunch of different ways over the last few hours, and I don’t even think I was on the right track so I didn’t include my attempt(s) in the code above. I can’t wrap my head around how to iterate over the checkboxes and array.remove() the array item of which it’s a part. Any help would be much appreciated.

  • 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-08T10:50:02+00:00Added an answer on June 8, 2026 at 10:50 am

    DEMO: http://jsfiddle.net/GKnHG/1/

    We can use the .splice() method.

    $('li').each(function() {
      if($(this).find('input:checked').length) {
         var val = $(this).find("span").html();
         var index = $.inArray(val, list);
         if (index >= 0) {
            list.splice(index, 1);
         }
      }
    });
    buildList();
    

    I moved the list build to another function (buildList()), as we call on it when the finish button is clicked, and at the end of the above block.

    Basically, we’re looping through each() of the li‘s, then checking if they have a :checked input inside them (length would be 0 if there are none).

    Once we know we’ve got a li with a checked checkbox, we can get use .html() to get a string out of the span element, and do a jQuery.inArray() check, which returns the index of the value in the array, or -1 if it can’t find any.

    if it’s greater than or equal to zero, we use the splice() method to delete the array item at that index. The second argument is how many items to delete.

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

Sidebar

Related Questions

This is how I get the tags of a body of text. var tags
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I have a text area in my form which accepts all possible characters from
I am currently running into a problem where an element is coming back from
I have a reasonable size flat file database of text documents mostly saved in
I have just tried to save a simple *.rtf file with some websites and
I would like to count the length of a string with PHP. The string
I was writing code for dragging mechanism which invokes to wait for small period
I've got a string that has curly quotes in it. I'd like to replace
I downloaded PostgreSQL from the official website and ran the .dmg installer. After that

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.