Quantity display issue in jQuery list

As someone who is new to jQuery and coding in general, I have spent several days working on a shopping list App using jQuery. While I have made progress, there are two specific issues that I am struggling with.

The quantity selector has been successfully implemented, but after selecting a number quantity and adding it, the item does not show up on my list. I'm having difficulty identifying where exactly I need to add the proper string in order for the quantity to appear in the list when the add button is clicked.

To view my code Demo, click here: http://jsbin.com/cetisobuhe/edit?html,js,output

Answer №1

You have overlooked adding the value of the second <input />:

let task = $('input').val() + ": " + $('input + input').val();

The code above seems to work in your current setup, although it's not quite right. Take a look at this:

Result:


Improved Version

Instead of the following structure:

<input type="text" id="new-text" placeholder="Add item to list"/>
<input type="number">
var new_task = $('input').val() + ": " + $('input + input').val();

It would be more beneficial to utilize:

<input type="text" id="new-text" placeholder="Add item to list" />
<input type="number" id="quantity" />
let task = $('#new-text').val() + ": " + $('#quantity').val();

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

What is the best way to navigate through a div element contained within another div element using jQuery

I am currently working on creating an ajax search bar using jQuery. I have encountered a roadblock where I need to navigate through dynamically created div elements within a larger div based on user input. Essentially, the divs are generated in response to ...

Navigate the scroll bar horizontally one by one instead of all at once, due to a width problem

The issue I'm facing involves determining the correct width for scrolling left or right. This results in the navigation tabs not scrolling correctly one by one. Each time I click the scroll right button, it adds more width than necessary and causes th ...

Displaying the recorded text in red when the stop button is clicked

I have a query about html, css, javascript. I've developed a game where numbers need to be clicked in a specific order. Upon clicking the stop button midway through the game, I want to display the record time in red color like shown in this image: e ...

Learn the steps to implementing AJAX into a shopping cart using CodeIgniter

I'm encountering difficulties trying to implement Ajax functionality in a shopping cart created with CodeIgniter. The problem arises when a user clicks on an item add button in a dropdown menu, causing the item to be added to a div named #cart through ...

Unsure how to proceed with resolving lint errors that are causing changes in the code

Updated. I made changes to the code but I am still encountering the following error: Error Type 'String' is not assignable to type 'string'. 'string' is a primitive, but 'String' is a wrapper object. It is recom ...

To restore the position of the chosen object in Three.js after clicking reset

I am facing an issue with resetting the position of my latest Object in three.js. Initially, my code consists of the following: function onDocumentMouseDown( event ) { event.preventDefault(); var vector = new THREE.Vector3( mouse ...

Transforming JSON object to an array of arrays using JavaScript

Attempting to extract specific values from a JSON object and store them in an array can be quite tricky. Below is an example of what this process might look like: Example: var obj = { "1":{"class":2,"percent":0.99,"box":[0.2,0.3,0.4,0.5]}, "2 ...

Establishing a read stream from a folder and transferring the entire contents of the folder to a MongoDB Bucket

I encountered an issue while attempting to save an entire directory to a MongoDB Bucket. Although the process is successful when I zip the file, I specifically need the files to be uploaded in their unzipped format into the bucket. However, when I try to ...

What is the process of combining two objects in TypeScript?

As part of my project, I am using two different get requests. The first request returns data in the form of: department: string[] The second get request provides an object structured like this: globalObj: { count: number[], admin: { department: ...

Utilizing jQuery Methods within Node.js

Recently delved into the world of node.js and created multiple pages (such as login, signup, blog, etc). If I desire an effect in which: 1. Hovering over the "News" button triggers a slider to appear downwards, To make adjustments to an image within ...

Having difficulties creating an HTML SVG Welcome screen

I'm currently working on developing an engaging splash screen for my mobile application. To accomplish this, I need to utilize SVG, HTML, and CSS in order to align with the app's architecture. The initial GIF represents the desired outcome that ...

The background image spanning across the entire screen, not just confined to the center

view image details here Can anyone explain why my background image for the main game is displaying like this? I want to set it for the entire screen as I have different backgrounds planned for the menu of the game and the game itself. Any suggestions to ma ...

Retrieve the attribute value from an HTML element in a JSON response using JavaScript

I received a JSON request result containing a blogger post. // API callback posts( { "version": "1.0", "encoding": "UTF-8", "entry": { "title": { "type": "text", "$t": "Vimeo Embed Video Post" ...

Ajax requests that are delayed to the same URL with identical data

While waiting for the back end developers to add a "cancel all" function, which would cancel all tasks tracked by the system, I am trying to create a workaround by cancelling each task individually. The cancellation REST service requires an ID in the form ...

What is the best way to navigate from the current node to its parent node using xpath?

I am currently working with an xpath that is based on class, and I am attempting to locate the parent element of it from the current position. Path 1 /html/body/div[2]/div[2]/div/div[2]/div/div[2]/div[2]/div[1]/div/div/p[8]/b[2]/a Path 2 /html/body/div[2 ...

Forwarding to another servlet based on the action of an HTML page

There are 2 servlets included in my code snippet @WebServlet("/Login") public class Login extends HttpServlet { ......... ......... } @WebServlet("/Create") public class Create extends HttpServlet { ......... ......... } Accompanied by an HTML page ...

Reordering items within an array of objects using JavaScript

I am working with an array of objects that needs to be sorted by category, and I also need to find the total number of items in each category. In the example provided below, all categories with "toys" should be grouped together for easier counting, like in ...

The image fails to appear while creating a PDF in AngularJS using pdfmake

I recently started using a fantastic pdf printing library called pdfmake in my angularjs SPA to generate PDF files. Everything was going smoothly until I tried to include images in the PDF. Strangely, when I added images, nothing happened - no errors, no e ...

Jquery Tablesorter no longer supports the StickyHeaders widget

After encountering a similar issue as described in this question, I found myself facing a problem. My table includes a stickyHeaders widget that fixes the headers while scrolling. Additionally, there are checkboxes within some of the table cells. Upon chan ...

I am in search of a specialized 3D camera with a unique effect

I am seeking assistance with animating a camera to replicate or closely resemble the effect seen in this demo: Any help would be greatly appreciated. ...