0

JavaScript submit button problem

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

26th Jun 2022, 9:26 PM
Ausgrindtube
Ausgrindtube - avatar
6 Réponses
+ 5
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
26th Jun 2022, 10:29 PM
Lisa
Lisa - avatar
+ 2
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.
27th Jun 2022, 8:23 AM
Lisa
Lisa - avatar
+ 2
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).
27th Jun 2022, 2:37 PM
Lisa
Lisa - avatar
+ 1
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.
27th Jun 2022, 2:50 PM
Ausgrindtube
Ausgrindtube - avatar
0
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)
27th Jun 2022, 7:54 AM
Ausgrindtube
Ausgrindtube - avatar
0
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!
27th Jun 2022, 2:22 PM
Ausgrindtube
Ausgrindtube - avatar