Skip to content Skip to sidebar Skip to footer

Show Sum Of Dynamic Radio Input Element And It Should Also Show When Click On Another Radio Input Element

I'm working on a project where I want to show total price accordingly when extra room option selected by the traveler. It is easy to do when the number of travelers is static but

Solution 1:

I haven't looked at all the code, but you seem to be setting up event handlers for the buttons. This is an asynchronous action that will fire when the button is pressed. However your total price is not wanting for the event to fire so won't be affected. You need to put the total price calculation in the callback function of the event. This is a common Javascript mistake because the asynchronous nature is tricky to understand. There is lots of material on the web to explain this - make sure you understand the concepts and don't try to cut and paste code

In the second res calculation you are overwriting the res value calculated for extra room1 instead of adding the values together. To make it clearer, call the first res something like extraRoom1Total and the second extraRoom2Total and then add them together. This will make the code easier to understand and therefore easier to debug and maintain

Post a Comment for "Show Sum Of Dynamic Radio Input Element And It Should Also Show When Click On Another Radio Input Element"