I am having difficulties in assigning double value (for example 124.00) of label text in asp.net. This label is in content page of .net master page.
But I am having the following two problems:
<script type="text/javascript">
var totalAmount = 0; //Defined global variable;
function addval(vals) //I am passing vals(Double from sever side)
{
totalAmount = totalAmount + vals;
(document.getElementsByTagName("<%= lblCurrentProductTotal.ClientID %>")).value= totalAmount.toString();
}
</script>
-
Each time “clickCh” is called; this sets the
totalAmount(a global variable) with the parameter passed. It’s like if I pass145first time it assigns as"0145"and second time if I pass156the totalAmount becomes"0145156"as I am expecting it to add as145+156=301. -
It’s not assigning the value to the label “lblCurrentProductTotal”
Please let me know if i am missing something.
Thanks in advance!
You are concatenating strings instead of adding doubles.
Either make sure that vals is passed as a number or turn it into a number using parseFloat like below.