I am new in javascript. Can someone help me with this code. it's really simple but I dont get it. my HTML code: <script src="static/js/script1.js"></script> </head> <body> <div class="wrapper"> <header id="header"> <h1>Programmeren 2013</h1> <img src="static/image/hamburger.jpg" id="hamburger" /> <img src="static/image/patat.jpg" id="patat" /> <img src="static/image/frikandel.jpg" id="frikandel" /> <div id="berichtvenster"> <p> Welkom bij het menu van de dag. het menu van de dag bestaat uit patat, hamburger en frikandel. Maak uw keuze en vul deze in het invulveld in. </p> <p>Wat wil je bestellen? <br/> <input type = "text" id ="keuze"> </p> <!-- <input type = "button" id="klik" onclick = "bestellen()" value = "bestel" > --> <input type="button" onclick="bestellen()" value="keuze"/> <!-- <button onclick="bestellen()">Bestel</button> --> </div> </header> My javascript code: window.onload = function () { 'use strict'; var bestellen = function() { var keuze = document.getElementById("keuze").value; }; var hamburger = {VoedselNaam:"hamburger", prijs:1.50}; var patat = {VoedselNaam:"patat", prijs:1.75}; var frikandel = {VoedselNaam:"frikandel", prijs:1.85}; var message = "wil je wat bestellen?"; var huidigePrijs = 0; var Prijsbestelling = 0; var bestelling = keuze; document.write("uw bestelling:") switch (bestelling) { case "hamburger": Prijsbestelling += hamburger.prijs; huidigePrijs = hamburger.prijs; break; case "patat": Prijsbestelling += patat.prijs; huidigePrijs = patat.prijs; break; case "frikandel": Prijsbestelling += frikandel.prijs; huidigePrijs = frikandel.prijs; break; default: alert("Kies iets dat op het menu staat."); continue; } //console.log(bestelling + " " + huidigePrijs); document.write(bestelling + " " + huidigePrijs); message = "Wil je nog iets bestellen?"; } //console.log("de prijs van uw bestelling bedraagt" + " " + Prijsbestelling + " " + "euro"); document.write("de prijs van uw bestelling bedraagt" + " " + Prijsbestelling + " " + "euro"); }(); Uncaught ReferenceError: keuze is not defined 6 Uncaught ReferenceError: bestellen is not defined when i click on button basically I want to make an order program. if the user types in for example: "hamburger" the price wil go up. Please help me
Please (a.u.b) use coding tags. [ code ] or [ php ] and second, i think you are missing a } somewhere... but not shure due the fact your code is unreadable in this style.
Your script is just gibberish, even once formatted. You've got a function called bestellen, that you aren't even returning a value on, but are setting a variable local in scope to it. "keuze" doesn't even EXIST outside "bestellen"... so when you try to define bestelling as keuze there's nothing to assing it TO. You then try to run a switch statement on a variable that by all rights should be null. Just what are you even trying to do?!? Oh, and you do know that document.write after onload will erase the ENTIRE document, right?