I'm trying to add up a specific input id value that's inside of a li tag. But it only gets the first number. I don't know how to get the second and third to work. I am very new to javascript. heres how the code looks like.
HTML
<li id="Pallet1" class="inactive">
<span class="itemNumber">1</span>
<input type="text" name="weight" placeholder="Pallet Weight (lbs)" id="QT" class='weight'/>
</li>
<li id="Pallet1" class="inactive">
<span class="itemNumber">2</span>
<input type="text" name="weight" placeholder="Pallet Weight (lbs)" id="f"/>
</li>
<li id="Pallet1" class="inactive">
<span class="itemNumber">3</span>
<input type="text" name="weight" placeholder="Pallet Weight (lbs)" id="f2"/>
</li>
<span id="total"></span>
javascript
$(".weight").keyup(function(){
var totalweight = $(".weight").val();
var totalweight2 = $("#f").val();
var totalweight3 = $("#f2").val();
if(totalweight2 == "" && totalweight3 == ""){
var total = totalweight;
}
if(totalweight3 == ""){
var total = Number(totalweight)+Number(totalweight2);
}
//this must add up
if(totalweight != "" && totalweight2 != "" && totalweight3 != ""){
var total = Number(totalweight)+Number(totalweight2)+Number(totalweight3);
}
$("#total").text(total);
if(total == ""){
$("#total").text("0");
}
});
ID's should be UNIQUE