mercredi 23 octobre 2019

Divide sum as a result of checkboxes toggled javascript

I'm having an issue. I have an accumulated sum of gathered donations, ex. 10€. Then I have a number of NGO's that you can choose to donate to. You have the opportunity to toggle on/off which NGO's you would like to support. Either you can choose to donate to all of them which means each NGO will receive 10€ / 3 = 3,33 € each. You can choose two and the allocation is going to be 10 € / 2 = 5€ each etc.

I'm having issues of finding a way to do this in javascript. Could you lead me the right way? Thanks.

My HTML atm:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>

    <script src="Velgørenhed.js"></script>

    <link rel="stylesheet" type="text/css" href="Velgørenhed.css"/>

</head>
<body>

<!-- Tilbage knap  -->
<button id="tilbage" onclick="goBack()">Tilbage</button>

<script>
    function goBack() {
        window.history.back();
    }
</script>


<form action="/action_page.php" method="get">
    <input type="checkbox" name="organisation" value="WHO" checked> Vælg velgørenhedsorgsnisation WHO<br>
    <input type="checkbox" name="organisation" value="Plastic Change" checked> Vælg velgørenhedsorgsnisation Plastic Change<br>
    <input type="checkbox" name="organisation" value="Sea Turtle Conservancy" checked> Vælg velgørenhedsorgsnisation Sea Turtle Conservancy<br>
    <input type="submit" value="Submit">
</form>



<p>y = 5, calculate x = y / 3, and display x:</p>

<button onclick="myFunction()">Try it</button>

<p id="demo"></p>

<script>
    function myFunction() {
        var y = 5;
        var x = y / 3;
        document.getElementById("demo").innerHTML = x;
    }
</script>






<!-- Log ud knap -->
<button id="logOut" onclick="logOut()">Log ud</button>

<script>
    function logOut() {
        document.location.href = "1logInd.html";
    }
</script>




</body>
</html>



Aucun commentaire:

Enregistrer un commentaire