https://code.sololearn.com/WKLNycuIxaF9/?ref=app I've been playing around with the Code Repo from the Web Development course and for some reason my ticket buying section doesn't work the way it should. The first time you type in the amount of tickets, then choose a ticket type, then the class and hit submit the total will alert NaN! or undefined or 0€. If you the change the class (for example) and hit submit again, you'll see the correct total. The correct total also seems to appear if you hit reset before you input any data. What am I missing? Do I have my functions in the wrong place? Why does the "send a message" part work fine? Any help and/or guidance is highly appreciated. Thanks
6/26/2022 9:26:00 PMAusgrindtube
6 AnswersNew Answer
For demonstration purposes, I removed everything in the js that didn't seem relevant for price calculation and wrote a basic version. You find comments in the js tab. I slightly changed the html (added a class, removed js functions) https://code.sololearn.com/W1z7Pk1lZ9kb/?ref=app
I think I misunderstood what you tried to do. If you only want to change on clicking submit, just don't add the calcPrice function to the other input fields.
I didn't do the code repo, so I wasn't sure. I thought you tried to update immediately as it seemed that you tried to attach click events on the radio buttons (in the initial version).
I think I took that from the code repo. I believe they were kind of upscaling the code, same as having the variables at the beginning, it was set and as you progress through the lessons they change what the site needs etc.
Hi Lisa, thanks! However, this updates before you hit the submit button instead of holding off the calculation until the user hits submit. I can see you have cleaned up the JS a lot and I'll play around with it. (I did manage earlier to get the site to do almost the same thing but it calculated when the user input the amount of tickets - which is why I had it at the top of the ticket section)
It's very normal for me to write something that is misunderstood. Sorry about that! https://code.sololearn.com/WPyzoehow03g/?ref=app It took some tinkering, but I by Jove, I think we pulled it off! Vielen herzlichen Dank Lisa. Du bist ein Schatz!