I can't display a dynamic price. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

I can't display a dynamic price.

There are 2 selectors, the 1st to choose the product to buy, and the second to choose the quantity of this product, then at the end of my functions, it should display the price the user has to buy (product's price * quantity), but nothing appears :,(. So please can someone check my inner HTML code, and tell me how to correct my mistake(s), and maybe some tips and tricks to improve my code, and please don't answer me to use jQuery, because I haven't learnt it. I thank every advises :) my project : https://code.sololearn.com/W01KYK017LSt/#html

15th Feb 2017, 5:12 PM
San_Antonio
San_Antonio - avatar
4 Answers
+ 3
You have several mistake in your js: - You cannot getElementById with a "name" attribute. - You cannot have identifiers ( names, id, class ) starting with a digit ( only a letter and some other chars, but not all: start with a letter, and compose only from digit, letter, underlines, avoid dashes, dot... all typo sign can being operators ^^ ) - You cannot write: 'var myvar("500");' as 'var' suppose a variable declaration, while 'myvar("500")' is a function call, with an identifier ( name ) not previously declared... ( this is the error targeted by running your script actually ). In the same way, you cannot use them in 'changementPrice' with this wrong syntax. - 'changementType' and 'changementQuantity' are both your function names and the pseudo variable declarations. Without the keyword 'var', you will call infinitly the function ( not really, you will have quickly a memory limit problem, as each call to a function is stored on a stack, with his context and unstackin on return: in the case of infinite nested call, you will fill quickly the memory ) ... Maybe there are others: I can't really debug more further without correcting ( if not rewriting ) your code ;) You need to already try to fix this :P
15th Feb 2017, 6:25 PM
visph
visph - avatar
15th Feb 2017, 5:13 PM
San_Antonio
San_Antonio - avatar
+ 2
Thanks a lot Visph, it's the 2nd time you're correcting my code, then you answer quickly to my questions with precision, it's very cool from you to spend all your time correcting my bloody messy codes and JS big mistakes, just for me. You should become teacher ;). +rep Visph + like + sub + love + .... :). thx
15th Feb 2017, 6:51 PM
San_Antonio
San_Antonio - avatar
+ 1
where is the code you are talking about?
15th Feb 2017, 5:07 PM
fjvfgvjgggfr5yue3