Adeel Aslam
Adeel Aslam

Reputation: 1294

javascript calculation formula is not working

I have following JavaScript function to make some calculation with textboxes but when I call this function on textbox the it doesn't works. Here is my JS code

Update

<script type="text/javascript" language=javascript>
function calc()
{
var pkrusd;
var pkrusd = parseFloat(document.getElementById("<%=txtpkrusd.ClientID %>").value, 10); 
var ratelb;
ratelb = parseFloat(document.getElementById("<%=txtRatelb .ClientID %>").value, 10); 
var res;
res = parseFloat(document.getElementById("<%=txtF5.ClientID %>").value, 10); 
res=pkrusd*ratelb;
}
</script>

<asp:TextBox ID="txtpkrusd" runat="server" BackColor="Yellow" style="text-align:right" onkeyup="calc()"></asp:TextBox>
    <asp:TextBox ID="txtRatelb" runat="server" BackColor="Yellow" Style="text-align: right" onkeyup="calc()"></asp:TextBox>

Please any one help me to find that what exactly i am missin in the code.

Upvotes: 1

Views: 145

Answers (2)

Just_Mad
Just_Mad

Reputation: 4077

Check your id's in the script. You need to use txtRatelb instead of txtratelb. They are case-sensitive.

Upvotes: 0

Blender
Blender

Reputation: 298046

Your variables aren't numbers. They are strings, so addition just concatenates them together.

Cast them to integers:

var pkrusd = parseInt(document.getElementById('txtpkrusd').value, 10);

Or floats:

var pkrusd = parseFloat(document.getElementById('txtpkrusd').value);

Upvotes: 4

Related Questions