Transferring an object from one inventory to another

I'm in the process of developing a task manager that enables users to add and remove tasks. I am also working on enabling the ability for users to transfer tasks from one list to another. The current code I have written doesn't seem to be functioning as expected, and I suspect there might be an issue within my JavaScript implementation.

HTML:

<input type='checkbox' id="togglelist1" class='arrow'/>
  <label for="list1menu">
    <input type="text" name="newlist1" value="" spellcheck="false" placeholder="New List" id="newlist1">
    <ul id="list1UL">
      <li><input type="checkbox" id="newlist1item" class="right-margin"/><label>List1</label> <button type="button" class="deletelist"> </button> <button type="button" class="addtolist2"></button></li>
    </ul>
  </label>

<input type='checkbox' id="togglelist2" class='arrow'/>
<label for="list2 menu">
  <ul id="list2UL" class='list2UL'>
    <li><input type="checkbox" id="newlist2item" class="right-margin"/><label>List2</label> <button type="button" class="deletelist"></button></li>
  </ul>
</label>

JavaScript:

$(() => {
  $('input').on('keypress', function(e) {
    if (e.keyCode == 13) {
      const newList1 = $(this).val();
      if (newList1) {
        var li = $("<li><input type='checkbox' id='newlist1item' class='right-margin'/><label>List1</label> <button type='button' class='deletelist'> </button> <button type='button' class='addtolist2'></button></li>");
        $('#list1UL').append(li);
        $(this).val("");
        localStorage.setItem("list1UL", value);
      }
    }
  });
  $(document).on("click", ".deletelist", function() {
    $(this).parent().remove();
  });
  $(".addtolist2").on( "click", function() {
    $(".addtolist2").css("opacity", 1.5 - $(".addtolist2").css("opacity"));
    $(".addtolist2").toggleClass("list2UL");
    $('#list1UL input:checked').parent().clone().appendTo('#list2UL');
});
});

CSS:

#togglelist1 {
  cursor: pointer;
  position: absolute;
  background: url('list1.png') no-repeat;
  height: 30px;
  width: 30px;
  background-size: 100%;
  display: none;
}

#togglelist2 {
  cursor: pointer;
  position: absolute;
  background: url('addtolist2.png') no-repeat;
  background-size: 100%;
  display: none;
}

____List 1____

label[for="list1menu"] {
  display: none;
  text-decoration: none;
  position: absolute;
  bottom: 250px;
  left: 250px;
  width: 680px;
  height: 540px;
}

...

____List 2____

label[for="list2menu"] {
  display: none;
  text-decoration: none;
  position: absolute;
  bottom: 250px;
  left: 250px;
  width: 680px;
  height: 540px;
}

...

Answer №1

Here is a simple solution for task management that allows you to add, edit, and delete tasks easily.

//Document is the DOM can be accessed in the console with document.window.
// Tree is from the top, html, body, p etc.

//Problem: User interaction does not provide the correct results.
//Solution: Add interactivity so the user can manage daily tasks.
//Break things down into smaller steps and take each step at a time.


//Event handling, uder interaction is what starts the code execution.

var taskInput=document.getElementById("new-task");//Add a new task.
var addButton=document.getElementsByTagName("button")[0];//first button
var incompleteTaskHolder=document.getElementById("incomplete-tasks");//ul of #incomplete-tasks
var completedTasksHolder=document.getElementById("completed-tasks");//completed-tasks


//New task list item
var createNewTaskElement=function(taskString){

var listItem=document.createElement("li");

//input (checkbox)
var checkBox=document.createElement("input");//checkbx
//label
var label=document.createElement("label");//label
//input (text)
var editInput=document.createElement("input");//text
//button.edit
var editButton=document.createElement("button");//edit button

//button.delete
var deleteButton=document.createElement("button");//delete button

label.innerText=taskString;

//Each elements, needs appending
checkBox.type="checkbox";
editInput.type="text";

editButton.innerText="Edit";//innerText encodes special characters, HTML does not.
editButton.className="edit";
deleteButton.innerText="Delete";
deleteButton.className="delete";
...


/* Styling */
body {
  background: #fff;
  color: #333;
  font-family: Lato, sans-serif;
}
.container {
  display: block;
  width: 400px;
  margin: 10px auto 0;
}
...

<html>
  <head>
    <title>Todo App</title>

  </head>
  <body>
    <div class="container">
      <p>
        <label for="new-task">Add Item</label><input id="new-task" type="text"><button>Add</button>
      </p>
      
      <h3>Todo</h3>
      <ul id="incomplete-tasks">
        <li><input type="checkbox"><label>Pay Bills</label><input type="text"><button class="edit">Edit</button><button class="delete">Delete</button></li>
        ...
        
      </ul>
      
      <h3>Completed</h3>
      <ul id="completed-tasks">
        <li><input type="checkbox" checked><label>See the Doctor</label><input type="text"><button class="edit">Edit</button><button class="delete">Delete</button></li>
      </ul>
...

Answer №2

Seems like there is an issue with your JavaScript code in this section

$(".addtolist2").on( "click", function() {
  $(".addtolist2").css("opacity", 1.5 - $(".addtolist2").css("opacity"));
  $(".addtolist2").toggleClass("list2UL");
 $('#list1UL input:checked').parent().clone().appendTo('#list2UL');
});

The first two lines are handling CSS changes and toggling classes when the button is clicked, but the third line seems to be doing something unusual. It appears that you're trying to copy an item from the first list to the second list when the corresponding button next to it is clicked.

If that's the case, here is a corrected version of the code snippet for achieving the same functionality:

$("addtolist2").on("click", function(){
 $(this).parent().clone().appendTo("#list2UL");
});

Please keep in mind that this code does not remove the original element from list1. If you want to also remove it, you can add $(this).parent().remove()

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

How can I stop iOS mobile browsers from automatically opening apps when I click on links?

Recently, I discovered an issue with my website when accessed on mobile (iOS). The links to external websites, such as Amazon product links, are causing the Amazon app to open instead of simply opening a new tab in the browser. The HTML code for these lin ...

Issue encountered: Unforeseen command: POST karma

Whenever I try to run my test cases, I encounter the following error message: Error: Unexpected request: POST data/json/api.json it("should $watch value", function(){ var request = '/data/json/api.json'; $httpBackend.expectPOST(reque ...

Generate a custom comment page for every URL identifier

I am currently working on creating a PHP comment page that displays unique comments for each specific URL ID. However, I have encountered an issue where the comment page is shared among all URLs. I understand that I need to add the URL ID (bug ID) to the M ...

Is there a way to change a mandatory field to optional in SuiteCRM?

I have two fields, field-A and field-B. The behavior of field-B depends on the value selected in field-A. If field-A has a value of 1, then field-B becomes a required field. To achieve this, I utilize SuiteCRM's addToValidate JavaScript function. How ...

Concealing the ellipsis in the will_paginate function of Rails

I'm currently utilizing will_paginate to manage a large number of values, but I am struggling to find a way to hide the "..." portion and the page numbers following it. Here is my current setup: https://i.stack.imgur.com/f2Tt8.jpg However, what I wou ...

Setting up redux with Next.js: a step-by-step guide

After setting up redux in this manner, everything is functioning properly. The _app.js file has been reorganized as follows : import App from 'next/app'; import { Provider } from 'react-redux'; import withRedux from 'next-redux-wr ...

Encountering a Typescript error while attempting to remove an event that has a FormEvent type

Struggling to remove an event listener in Typescript due to a mismatch between the expected type EventListenerOrEventListenerObject and the actual type of FormEvent: private saveHighScore (event: React.FormEvent<HTMLInputElement>) { This is how I t ...

What is the process for cancelling a pending request using jQuery in JavaScript Selenium?

My website has a high volume of users clicking on one button. Waiting for long-pending ajax requests to get responses, sometimes over a minute, seems nonsensical. I understand how to wait for the response, but how can I cancel it? How do I cancel all pend ...

capturing the value of a button during the onChange event

I'm currently trying to retrieve the button value within an onChange event. My goal is to then bind this value to state, but unfortunately, I am receiving an empty value. <button onChange={this.handleCategoryName} onClick={this.goToNextPage}> ...

What is the process for incorporating the !important declaration into a CSS-in-JS (JSS) class attribute?

I'm currently exploring the use of CSS-in-JS classes from this specific response in conjunction with a Material UI component within my React project. In order to override the CSS set by Bootstrap, I've decided to utilize the !important modifier. ...

Placing a moveable object in a designated spot for dropping at the desired location

I've been attempting to clone and drop a draggable object at the exact position within a droppable area where the drop event takes place. While I have come across examples online that demonstrate appending draggables to droppables, they all tend to re ...

Having trouble with the border styling on my HTML input form

I've been struggling to add a solid black border around the text input in my form. However, no matter what I try, the border doesn't seem to style correctly. Here's the code snippet I'm using: #forminput { border: solid black !import ...

Inquiry to an outside domain

I need to send a request to an external domain, ensuring that the parameter is correctly sent to a PHP file on the external server. However, I'm facing an issue where "request.responseText" always returns empty. Any assistance in this matter would be ...

Move the camera in Three.js along a path between two vectors

I created a basic scene and came across a tutorial at to help me move the camera: var timer = new Date().getTime() * 0.0005; camera.position.x = Math.floor(Math.cos( timer ) * 200); camera.position.z = Math.floor(Math.sin( timer ) * 200); However, I n ...

PHP receive apostrophe from $_GET array

Similar Question: “slash before every quote” issue Hello there, I am currently attempting to utilize $_GET in order to transmit the contents of a text box to another php file. However, whenever I include single (') or double (") quote ...

Display a loading spinner dialog using Jquerymobile until the page finishes loading

I am facing an issue with my app where I need to show a Loading dialog while sending data from the first page to the server. The goal is to display the Loading dialog until the send operation (posting to server) is complete and then proceed to page two. I ...

Identifying Inaccurate Device Date Using JavaScript

Is there a way to detect if the device's date is inaccurate using javascript? (For example, displaying an alert if the current date is 2016/6/16 but the device date is 2016/6/15) ...

What is the best way to manage events within datalist options using Vue.js?

I have a specific requirement where I need to implement a feature in my data list. When a user selects an option from the datalist, I must update other input fields based on that selection. Below is the code snippet for my input field and Datalist: <i ...

Is there a way to modify the standard width of semantic-ui sidebars?

I'm trying to adjust the width of semantic-ui sidebars, which are originally 275px wide. Where should I include the css/js code to make them wider or narrower? Here is their default code: .ui.sidebar { width: 275px!important; margin-left: -275 ...

Avoid Updating State After Adding Row in material-table

When utilizing the material-table library, my goal is to display a different component upon adding a row. Although the code functions as expected, I encountered the following error in the console: Warning: Can't perform a React state update on an unm ...