Jump to content

Adding and Deleting


akhandafm17

Recommended Posts

<script>
       var nr = 0
       function nieuwLijn(demo) {
           var blok = document.getElementById(demo);
           var lijn = document.createElement("hr");
           blok.appendChild(lijn);
       }
       function verwijderLijn(demo) {
           blok = document.getElementById(demo);
           lijnen = blok.getElementsByTagName("hr");
           if (lijnen.length > 0) {
               blok.removeChild(lijnen[lijnen.length - 1]);
           }
       }
       function newParagraaf(demo) {
           var blok = document.getElementById(demo);
           var paragraaf = document.createElement("p");
           paragraaf.innerHTML = "Dit is paraagraaf nr." + nr.toString();
           nr++
           blok.appendChild(paragraaf);
       }
       function VerwijderParagraaf(demo) {
           var blok = document.getElementById(demo);
           var paragraaf = blok.getElementsByTagName("p");
           if (paragraaf > 0) {
               blok.removeChild(paragraaf[paragraaf.length - 1]);
           }
           
       }
      
   </script>

 <button type="button" onclick="nieuwLijn('demo1')">maak</button>
    <button type="button" onclick="verwijderLijn('demo1')">verwijder!</button>
    <button type="button" onclick="newParagraaf('demo1')">paragraaf</button>
    <button type="button" onclick="VerwijderParagraaf('demo1')">verparagraaf</button>
    <div id="demo1"></div>
    <p id="demo"></p>

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

 

 <script>
        var totaal =0.0
        var namen =""
        function verwerking() {
            naam = document.getElementById("naam").value;
            bedrag = Number(document.getElementById("bedrag").value);
            if (namen == "") {
                naam == namen;
            }
            else {
                namen = namen + "," + naam;
            }
            totaal += bedrag;
            uitvoer = document.getElementById("uitvoer");
            txtTotaal = document.getElementById("totaal");
            uitvoer.value = uitvoer.value + "\n" + naam + "," + bedrag
            txtTotaal.value = totaal + "euro";
        }
    </script>

<input id="naam" type="text" />
    <input id="bedrag" type="number" />
    <input id="verwerk" type="button" value="verwerk" />
    <textarea id="uitvoer" rows="2" cols="20"></textarea>
    <input id="totaal" type="text" />

-----------------------------------------------------------------------------------------------------------------------------------------------------------------------

<script>
        function naamenbedrag() {
            var invoerok = false
            while (!invoerok) {
                var invoer = prompt("geef naam en betaald bedrag");
                if (invoer = "") {
                    invoerok = true;

                }
                else {
                    invoer = invoer.split(",");
                    if (isNaN(invoer[1])) {
                        invoerok = false
                    }
                    else {
                        invoerok = true;
                    }
                }
            }
            return invoer;
        }
        function verwerkbetaling() {
            var hasended = false;
            var totaal = 0.0;
            var namen = "";
            while (!hasended) {
                invoer = naamenbedrag();
                if (invoer == "") {
                    hasended = true;
                }
                else {
                    Naam = invoer[0];
                    bedrag = Number(invoer[1]);
                    totaal += bedrag;
                    Namen = Namen == "" ? Naam : Namen + "," + Naam;
                }
            }
            alert(
                "Totaalbedrag: " + Totaal + "\n" +
                Namen + " hebben betaald."
        }

    </script>

Link to comment
Share on other sites

Don't know if there is a problem with your code as I don't see any questions.

However, in your first four functions you define "blok" as a  local variable in 3 of them and a global in the other.

	       function verwijderLijn(demo) {
           blok = document.getElementById(demo);
           lijnen = blok.getElementsByTagName("hr");
           if (lijnen.length > 0) {
               blok.removeChild(lijnen[lijnen.length - 1]);
           }
       }
	

Was that intentional?

 

Link to comment
Share on other sites

4 hours ago, JMRKER said:

Don't know if there is a problem with your code as I don't see any questions.

However, in your first four functions you define "blok" as a  local variable in 3 of them and a global in the other.

 


	       function verwijderLijn(demo) {
           blok = document.getElementById(demo);
           lijnen = blok.getElementsByTagName("hr");
           if (lijnen.length > 0) {
               blok.removeChild(lijnen[lijnen.length - 1]);
           }
       }
	

 

Was that intentional?

oh sorry i forgot the question. I wanted to ask if you saw some errors in these 3 liitle javascript projects.

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...