mercredi 30 octobre 2019

How can I change the value of the checkboxes using javascript

I have a function that checkes the value of a checkbox and changes it you click on the checkbox. The value has to change from 0 to 1. This problem occures with every checkbox and I can't find any information to help me. click on the checkbox the console prints out "Uncaught TypeError: teVoet is not a function at HTMLInputElement.onclick (deelEen.php:152)"

this is html code

<!-- Vervoer -->
                <legend><span class="section">10</span>Vervoer</legend>
                <p>Hoe komt de leerling naar school</p>
                <p><input type="checkbox" value="0" name="teVoet" onclick="teVoet()" ID="teVoet" />&nbsp;Te voet</p>
                <p><input type="checkbox" value="0" name="fiets" onclick="fiets()" ID="fiets" />&nbsp;Fiets</p>
                <p><input type="checkbox" value="0" name="motorfiets" onclick="motorfiets()" ID="motorfiets" />&nbsp;Motorfiets</p>
                <p><input type="checkbox" value="0" name="bus" onclick="bus()" ID="bus" />&nbsp;Bus</p>
                <p>
                    Buzzypas&nbsp;
                    <select name="buzzypas">
                        <option value="nee">Nee</option>
                        <option value="ja">Ja</option>
                    </select>
                </p>
                <p><input type="checkbox" value="0" name="trein" onclick="trein()" ID="trein" />&nbsp;Trein</p>
                <p>abonnement voor traject&nbsp;<input type="text" name="traject" /></p>
                <p><input type="checkbox" value="0" name="auto" onclick="auto()" ID="auto" />&nbsp;Auto</p>

And this is my javascript code

//scripts deelEen.php
function teVoet() {
    if (document.getElementById("teVoet").value == 0) {
        document.getElementById("teVoet").value = 1;
    } else {
        document.getElementById("teVoet").value = 0;
    }
}

function fiets() {
    if (document.getElementById("fiets").value == 0) {
        document.getElementById("fiets").value = 1;
    } else {
        document.getElementById("fiets").value = 0;
    }
}

function motorfiets() {
    if (document.getElementById("motorfiets").value == 0) {
        document.getElementById("motorfiets").value = 1;
    } else {
        document.getElementById("motorfiets").value = 0;
    }
}

function bus() {
    if (document.getElementById("bus").value == 0) {
        document.getElementById("bus").value = 1;
    } else {
        document.getElementById("bus").value = 0;
    }
}

function trein() {
    if (document.getElementById("trein").value == 0) {
        document.getElementById("trein").value = 1;
    } else {
        document.getElementById("trein").value = 0;
    }
}

function auto() {
    if (document.getElementById("auto").value == 0) {
        document.getElementById("auto").value = 1;
    } else {
        document.getElementById("auto").value = 0;
    }
}



Aucun commentaire:

Enregistrer un commentaire