mardi 6 septembre 2016

show checked checkbox values on textarea javascript

i am trying to get all the checkbox checked values on input field provided. i am using javascript to get the values but it only shows one checked value, when i check another checkbox it displays the second one only. here is what i did so far:

<html>
<head>
<script type="text/javascript">
function checkbox(val){
document.getElementById("show").value = val;
}
</script>
</head>
<body>
    <form>
        <input type="checkbox" id="bk" name="vehicle" onClick="checkbox(this.value);" value="Bike">I have a bike<br></br>
        <input type="checkbox" id="cr" name="vehicle" onClick="checkbox(this.value);" value="Car">I have a car<br></br> 
        <input type="text" id="show" name="vehicle"><br>
        <input type="submit" value="Showe">
    </form> 
</body>
</html>

as i said this one only shows a single checked value, but i want to show all the checked value on the input field specified! Thanks!

Aucun commentaire:

Enregistrer un commentaire