Guide on accessing checkbox id in Vue3 and determining its checked status

<div>
  <input 
    type="checkbox" 
    class="delete-checkbox" 
    :id=this.products[index].sku  
    @click="setDelete(this.products[index].sku)" />
</div>

I'm currently working on a Vuex application and I need to trigger an event when this specific checkbox is checked. Unfortunately, I'm not sure how to achieve this functionality.

Any assistance would be greatly appreciated. Thank you!

Answer №1

Take a look at this code snippet below:

const example = {
  data() {
    return {
      items: [{id: 1}, {id: 2}, {id: 3}],
    };
  },
  methods: {
    handleDelete(id) {
      console.log('delete clicked for id: ' + id)
    }
  },
};
Vue.createApp(example).mount("#example");
<script src="https://unpkg.com/vue@next"></script>
<div id="example">
  <li v-for="(item, index) in items" :key="index">
    <input type="checkbox" class="del-checkbox" :id="item.id" @click="handleDelete(item.id)">
  </li>
</div>

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

Saving data inputted in a form using ReactJS and JavaScript for exporting later

What is the best way to save or export form input in a ReactJS/JS powered website? For example, if I have a form and want to save or export the data in a format like CSV after the user clicks Submit, what method should I use? Appreciate any advice. Thank ...

What is the best way to utilize an AngularJS directive to send a POST request with all parameters from a form?

I have created a custom AngularJS form with Stripe integration using a directive. You can view the Fiddle for this project here: https://jsfiddle.net/u5h1uece/. HTML: <body ng-app="angularjs-starter"> <script src="https://js.stripe.com/v3/"> ...

What is the best way to parse a JSON file and create a dynamic webpage using jQuery with the data from the

As someone who is new to working with Node.js and JSON, I am encountering some issues when trying to extract data from a JSON file. Below is the code that I have written: 'use strict'; const fs = require('fs'); let questsRawData = fs ...

Identify Bootstrap modal to modify destination of keypress input

I am working on a piece of code that detects keypress events and focuses input towards a searchbar with the id "search". $( document ).keypress(function() { $("#search").focus(); In addition, I have a bootstrap modal dialog containing input fields ...

What are some effective ways to manage MySQL queries using asynchronous functions in JavaScript?

Can anyone assist me with my issue? I am new to JavaScript (Node.js) and attempting MySQL queries, but it seems like nothing is being output. I'm unsure how to address this. async function processArguments() { var result_customer = []; for(le ...

Unexpected behavior with $routeChangeSuccess: Failing to trigger upon initial load (without any reported errors)

Trying to explain the complicated scenario I'm facing seems daunting, but I'll give it a shot. I have created a basic Spanish-English-Spanish dictionary lookup page featuring a text box, a Lookup button, and a div for displaying the results. Once ...

What is the significance of having a timer in a Redux reducer to prompt a re-rendering process?

Encountered some unusual behavior that I need to understand better Here is the code for my reducer. Strangely, the component linked to the redux state does not re-render with this code. Despite confirming through developer tools that the state updates cor ...

Switch out the view div element with ui-router

Currently, I am utilizing Angular ui-router to manage various views in the following manner: <div ui-view="header"></div> <div ui-view="nav"></div> <div ui-view></div> Upon Angular loading, the divs are automatically p ...

How can I make AWS SDK wait for an asynchronous call to finish executing?

Understanding the AWS SDK documentation can be a bit confusing when it comes to making asynchronous service calls synchronous. The page at https://docs.aws.amazon.com/sdk-for-javascript/v2/developer-guide/calling-services-asynchronously.html states: All ...

What sets apart `npm install --save-dev gulp-uglify` from `npm install gulp-uglify`?

I'm feeling perplexed regarding the npm installation process. Based on what I've gathered, there are several options available to me when installing modules: The -g option which saves modules globally --save-dev No arguments. Could someone cl ...

Finding the host name of a client machine using Node.js

Is there anyone who can assist me in obtaining the client's machine name or host name for authentication on my website, which is operating internally within my company domain? I attempted the code below but received the server's host name instead ...

Creating a function that writes to a file by utilizing the data input from

After running the provided code snippet, it successfully works in a standalone project. However, I am interested in making modifications to replace the variable "sample_text" with an output that is displayed in the terminal instead of being hardcoded int ...

Having trouble accessing the property 'top' of an undefined object in your Ruby on Rails project?

After thoroughly reviewing all the similar threads on SO regarding this error, none of them provided a solution that worked for me. Here is the flow of events: Go to the new Customer page, fill out the required fields, and click save Invoke a method in ...

Positioning a dropdown menu on top of a Google Map in React with JavaScript: Best Practices

I've been attempting to place a dropdown menu at a specific location on my Google Map, specifically in the top right (or top left is also acceptable). Below is the current output I am seeing: Here is the expected result: Modifications After trying ...

The issue of the callback not being triggered by the sinon.js fakeServer when making a $.ajax call was encountered

I am currently working on a jasmine specification that involves testing a jQuery plugin I created: describe "plugins", -> beforeEach -> @server = sinon.fakeServer.create() afterEach -> @server.restore() describe "reviewStatu ...

Having trouble with your angular.jg ng controller functioning properly?

Having trouble getting any content to show up from the media object! The plate object seems to be malfunctioning. <!DOCTYPE html> <html lang="en" ng-app="confusionApp"> <head> <meta charset="utf-8"> <met ...

Utilizing negative values in lineTo, strokeRect, and fillRect functions

Is it possible to input negative numbers into the drawing primitives of HTML5 canvas? For instance, if I apply a translation of (100,100), would I be able to draw a rectangle or line with coordinates (-25,-25)? Initial testing using lineTo seems inconclus ...

Is OnPush Change Detection failing to detect state changes?

Curious about the issue with the OnPush change detection strategy not functioning properly in this demonstration. My understanding is that OnPush change detection should activate when a property reference changes. To ensure this, a new array must be set e ...

A Guide to Setting the HTML Lang Attribute on a Specific Page in Next.js

I have a website built with Next.js that consists of several pages. Most of the pages are in English, but there is one page that is in French and does not have an English version. How can I assign the lang attribute to the HTML tag for this specific page ...

What is the best way to include a text input as the last option in a Select input form field?

I would like to implement a select input feature where users can choose from predefined options, with the added functionality of including a text input field as the last option for users who prefer to enter their own category. How can I achieve this? Curr ...