I am relatively new to Javascript and having some trouble with changing values.
Here is my Javascript:
function printResults(results, numMeals){
calories=Math.round(results);
protein= Math.round(results/4*.4);
carbs=Math.round(results/4*.3);
fats=Math.round(results/9*.3);
document.getElementById("calories").innerHTML="Total Calories: " + ('<input type="text" id= "totalCal">');
document.getElementById("totalCal").value=calories;
document.getElementById("protein").innerHTML="Grams of Protein: " + ('<input type="text" id="totalProtein">');
document.getElementById("totalProtein").value=protein;
document.getElementById("carbs").innerHTML="Grams of Carbs: " + ('<input type="text" id="totalCarbs">');
document.getElementById("totalCarbs").value=carbs;
document.getElementById("fats").innerHTML="Grams of Fat: " + ('<input type="text" id="totalFats">');
document.getElementById("totalFats").value=fats;
calories= Number(document.getElementById("totalCal").value);
protein= Number(document.getElementById("totalProtein").value);
carbs= Number(document.getElementById("totalCarbs").value);
fats= Number(document.getElementById("totalFats").value);
document.getElementById("search").innerHTML= ('<a class="btn" href="search/'+calories+'/'+protein+'/'+carbs+'/'+fats+'/'+numMeals+'">Find Meals</a><br>');}
And it edits these html input fields:
<div class="span2" style="text-align:left">
<span id="calories"> Total Calories: -</span><br>
<span id="protein"> Protein: -</span><br>
<span id="carbs"> Carbs: -</span><br>
<span id="fats"> Fats: -</span><br>
<span id="search"></span><br>
</div>
This works with setting the initial values, however, when I edit the value of the text field manually, it does not change the value upon submission. For example if the original calories are set to 2000 based on the calculations and then I edit the text field to 2500, my search still yields a value of 2000.
Find mealswith the initial search values? Then of course the link won't return the values if changed after?