get multiple checkbox value in javascript
<!DOCTYPE html>
<html>
<body>
<label>Check Which you have</label><br/>
<input type="checkbox" id="checkbox1" name="bike" value="Bike"> Bike <br/>
<input type="checkbox" id="checkbox2" name="car" value="Car"> Car <br/>
<input type="checkbox" id="checkbox3" name="home" value="Home"> Home <br/>
<button onclick="getValue()">Get Value</button>
<p id="p1"></p>
<script>
function getValue() {
var ele=[]
var bike = document.getElementById("checkbox1")
if(bike.checked){
ele.push(bike.value);
}
var car = document.getElementById("checkbox2")
if(car.checked){
ele.push(car.value);
}
var home = document.getElementById("checkbox3")
if(home.checked){
ele.push(home.value);
}
if(ele.length>0){
document.getElementById("p1").innerHTML = ele;
}
else{
document.getElementById("p1").innerHTML = "You Dont have any thing";
}
}
</script>
</body>
</html>
Also in JavaScript:
- wait for loop to finish javascript
- how to enter a line of javascript code in vscode without having to arrow out of parenthesis to add a semicolon
- turn number into array javascript
- jest async test fetch api
- check if object has method javascript
- video js toggle play pause
- navigate to route and refresh angular 6
- localecompare javascript
- how to clear terminal in vs code
- javascript generate 3 numbers 1 - 49
- double question mark javascript
- badlion client
- javascript remove property from object
- if in javascript
- Firebase: Firebase App named '[DEFAULT]' already exists
- javascript sleep settimeout
- js fucntion return array
- how to make a vowel counter in javascript
- how to run p5js in a particular section of page
- javascript json deserialize
- transformorigin gsap
- js set visibility
- js user add names to a list on screen
- submitting login and sign up forms using AJAX