Skip to content

All topics  /  Vue

Vue.Js Get Checked Value of Checkbox If Use Array As A Model

Vue ·

Hi Guys,

In this blog,I will explain you how to get checked value of checkbox if use array as a model in vue.js. I will show Get Checked Value of Checkbox If Use Array As A Model in vue.js. you can easyliy get checked value in array using vue.js

Here, I will give you full example for simply get checked value of checkbox if use array as a model using vue.js as bellow.

Example


<!DOCTYPE html>
<html>
<head>
  <title>Vue Js Get Checked Value of Checkbox If Use Array As A Model</title>
  <link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/5.0.0-alpha1/css/bootstrap.min.css">
  <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
</head>
<body class="bg-dark">
  <div class="container">
    <div class="col-md-7 offset-md-2  ">
      <div class="card mt-5">
        <div class="card-header">
          <h5>Vue Js Get Checked Value of Checkbox If Use Array As A Model</h5>
        </div>
        <div class="card-body">
          <div id="app">
            <input type="checkbox" id="php" value="php" v-model="checkedNames">
            <label for="php">php</label>
            <input type="checkbox" id="laravel" value="laravel" v-model="checkedNames">
            <label for="laravel">laravel</label>
            <input type="checkbox" id="html" value="html" v-model="checkedNames">
            <label for="html">html</label>
            <br>
            <span>Checked names: {{ checkedNames }}</span>
          </div>
        </div>
      </div>
    </div>
  </div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/1.0.18/vue.min.js"></script>
<script>  
new Vue({
  el: '#app',
  data: {
    checkedNames: []
  }
}) 
</script>
</body>
</html>

It Will help you...