Click here to Skip to main content
15,892,005 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have three textbox.one for totalfees.second for payfees.third for remainingfees.

totalfees is filled already when page load.payfees i have to enter.when i leave from textbox remainigfees calculated automatically.
for this i have to use javascript.i have try this..but i think i have problem in my javascript function.please help me.

function RemainingFees()
{
var v1=document.getElementById("ctl00_ContentPlaceHolder1_TabContainer1_TabPanel1_txt_totalfees");
var v2=document.getElementById("ctl00_ContentPlaceHolder1_TabContainer1_TabPanel1_txt_remainingFees");
var v=v1.value-v2.value;
document.getElementById("ctl00_ContentPlaceHolder1_TabContainer1_TabPanel1_txt_totalfees")=v.value;

}
Posted

Try:
document.getElementById("ctl00_ContentPlaceHolder1_TabContainer1_TabPanel1_txt_totalfees").value=v;

You have put .value on the wrong side.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 25-Jan-13 16:34pm    
Correct, a 5.
—SA
Sergey Alexandrovich Kryukov 25-Jan-13 16:45pm    
However, something else is missing before this line.
Before doing integer arithmetic operations, strings should be parsed with JavaScript parseInt(string).
Please see my answer. Your answer is of course credited...

And I deleted OP's re-post where I initially saw this question and answered. Tnank you for notification on this re-post.
—SA
In addition to correct answer by Zoltán Zörgő:

First bug I can see immediately:
C#
document.getElementById("txt_remainingfees")=v.value;


What is v.value?! Should be:
C#
document.getElementById("txt_remainingfees").value=v;


Besides, to get values from strings, you had to use parseInt(string):
http://www.w3schools.com/jsref/jsref_parseint.asp[^].

I would also advise to use jQuery. It would be:

C#
total=parseInt($("#txt_totalfees"));
fees = parseInt($("#txt_payFees"));
result = $("#txt_remainingfees");
result.value = total.value - fees.value;


Please see:
http://en.wikipedia.org/wiki/JQuery[^],
http://jquery.com/[^].

—SA
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900