Nick Garver Nick Garver - 7 months ago 29
HTML Question

Div field not updating

I am not sure why this field is not updating with the correct number. It is worth noting that for some reason that any number <1 is rounding in the alert() function. I think all the numbers are just getting rounded down but I don't know another method to get the value that won't do that? Any suggestions?

actual value = 0.03

var citrullineChoice = document.getElementById("citrulline").getElementsByClassName("on")[0].value;

alert returns 0

actual value = 0.03

var tyrosineChoice = document.getElementById("tyrosine").getElementsByClassName("on")[0].value;

alert returns 1

Code Here


Here is a fix for what you want:

I am passing the value to the function, instead of adding it as an attribute value to your element.

<li id="caffeinetwo" class="off" onclick="changeClass(this, 0.03)">250</li>

Also changed your changeClass a bit, so you won't need to change it if you want to add or remove an option in your creation bar.