1<!DOCTYPE html>
2<html>
3 <body>
4 <label>Check Which you have</label><br/>
5 <input type="checkbox" id="checkbox1" name="bike" value="Bike"> Bike <br/>
6 <input type="checkbox" id="checkbox2" name="car" value="Car"> Car <br/>
7
8
9 <input type="checkbox" id="checkbox3" name="home" value="Home"> Home <br/>
10 <button onclick="getValue()">Get Value</button>
11 <p id="p1"></p>
12 <script>
13 function getValue() {
14 var ele=[]
15 var bike = document.getElementById("checkbox1")
16 if(bike.checked){
17 ele.push(bike.value);
18 }
19 var car = document.getElementById("checkbox2")
20 if(car.checked){
21 ele.push(car.value);
22 }
23 var home = document.getElementById("checkbox3")
24 if(home.checked){
25 ele.push(home.value);
26 }
27 if(ele.length>0){
28 document.getElementById("p1").innerHTML = ele;
29 }
30 else{
31 document.getElementById("p1").innerHTML = "You Dont have any thing";
32 }
33 }
34
35
36 </script>
37 </body>
38</html>