C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Forums » .NET » General »

How to make one more TextBox values Addition ?


Posted Date: 04 Nov 2008      Posted By: seenu      Member Level: Gold     Points: 1   Responses: 2



Hi!
now i given Three(3) Textbox value add And Result display in TextBox4...suppouse you given TextBox1 & TextBox3 value(ex:100,200) but didn't given TextBox2 values in run time...TextBox2 value built in 0 automaticaly...At that time of running in webpage you make it to change Each & Every single digit value in any Textbox automaticaly change the Result value...

The javascript code as follows:

<script language="javascript" type="text/javascript">
function Fn_Add()
{
var first ="0"
var second="0"
var third="0"




if(document.getElementById ("TextBox1").value!="")
{
first =document.getElementById ("TextBox11").value
}
else
{
document.getElementById("TextBox1").value="0"
}
if(document.getElementById ("TextBox2").value!="")
{
second=document.getElementById ("TextBox2").value
}
else
{
document.getElementById("TextBox2").value="0"
}
if(document.getElementById ("TextBox3").value!="")
{
third=document.getElementById ("TextBox3").value
}
else
{
document.getElementById("TextBox3").value="0"
}

document.getElementById ("TextBox4").value=parseInt(first)+parseInt(second) + parseInt(third)

}
</script>





Responses

Author: Meena Mehra    05 Nov 2008Member Level: GoldRating: 3 out of 53 out of 53 out of 5     Points: 3

u can call this javascript function in onchange property of these three textboxes like---
<asp:TextBox ID="TextBox " runat="server" CssClass="cssTextInputNum" MaxLength="10" Width="75px" onchange="Fn_Add();"></asp:TextBox>



Author: ABCDE    05 Nov 2008Member Level: GoldRating: 2 out of 52 out of 5     Points: 5

Hi Seenivas,

You need to have a function that runs onchange. That way, when a value changes, the function is triggered and will recalculate the values.

For example:

<script type="text/javascript">
function recalc() {
// code to check textbox 1
. . .

// code to check textbox 2
. . .

// code to check textbox 3
. . .

// add them up, change the text
document.getElementById("TextBox4").value = tb1+tb2+tb3;
}
</script>
<input id="TextBox4" type="text" value="" onChange="java script:recalc();" />

Thanks



Post Reply

 This thread is locked for new responses. Please post your comments and questions as a separate thread.
If required, refer to the URL of this page in your new post.


Next : AdSense approval through dotnetspider
Previous : Regarding code snippet
Return to Discussion Forum
Post New Message
Category: General

Related Messages



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use