Click here to Skip to main content
15,920,596 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
hello programmers, got a problem here. As you see all i want is to automatically add all the vlues stored on all the text boxes. Ive tried many ways including setting textmaterial2 autopostbact to true and put the solution on txtTE2 but still it doesnt work. I dont know if my java script is correct. Plss help. Is there any possible solution here?
XML
<script language="javascript">
function keyUp() {
            if (document.getElementById("txtmaterial2").value == "") {
                document.getElementById("txtTE2").text == "";
            }
            else {
                document.getElementById("txtTE2").text = Round((CDbl(txtmealallowance2.Text) + CDbl(txttransportationallowance2.Text) + CDbl(txtPerDiem2.Text) + CDbl(txttransportation2.Text) + CDbl(txtaccomodation2.Text) + CDbl(txtmealven2.Text) + CDbl(txtconsultant2.Text) + CDbl(txtmaterial2.Text)), 2);
            }
        }
</script>
Posted
Comments
walterhevedeich 27-Jul-11 22:17pm    
Can you provide more details to it doesn't work? Does it error? Also, are you using master pages or user controls?
drkterror 27-Jul-11 22:48pm    
it doesnt have error sir but it isnt working.
drkterror 27-Jul-11 22:49pm    
sir im user control

CDbl is a vbscript function
do you have any custom designed function 'CDbl' in your javascript that you are calling?

some tips:

1. Use jquery to make your life simpler in javascript.
2.if using IE open developer bar (firebug in firefox) and debug your javascript, you can easily see your error.
 
Share this answer
 
Comments
walterhevedeich 27-Jul-11 23:25pm    
Good advice.
saxenaabhi6 27-Jul-11 23:47pm    
thanks, your dp is so innovative is that your idea ?
Try this code:
XML
<script language="javascript">
function sumquinto()
{
var Sumbog=0;
var val1= parseInt(document.getElementById("textbox1").value);
var val2= parseInt(document.getElementById("textbox2").value);
var val3= parseInt(document.getElementById("textbox3").value);
var val4= parseInt(document.getElementById("textbox4").value);
var val5= parseInt(document.getElementById("textbox5").value);
var val6= parseInt(document.getElementById("textbox6").value);
etc


if (val1 >=0)
{
Sumbog= Sumbog + val1
}
if (val2>=0)
{
Sumbog=Sumbog+val2
}
if (val3>=0)
{
Sumbog=Sumbog+val3
}
if (val4>=0)
{
Sumbog=Sumbog+val4
}
if (val5>=0)
{
Sumbog=Sumbog+val5
}
if (val6>=0)
{
etc
}
document.getElementById("txtTE2").value=Sumbog
}
</script>
<asp:TextBox ID="TextBox1" runat="server" onkeyup="sumquinto();"></asp:TextBox>
<asp:TextBox ID="TextBox2" runat="server" onkeyup="sumquinto();"></asp:TextBox>
<asp:TextBox ID="TextBox3" runat="server" onkeyup="sumquinto();"></asp:TextBox>
<asp:TextBox ID="TextBox4" runat="server" onkeyup="sumquinto();"></asp:TextBox>

and on your solution textbox dont add the onkeyup event.
 
Share this answer
 
v2
Comments
drkterror 27-Jul-11 23:12pm    
thanks sir it works ^_^
walterhevedeich 27-Jul-11 23:26pm    
5 for providing a working solution.
saxenaabhi6 27-Jul-11 23:46pm    
good to see janwel now posting answers :)
janwel 28-Jul-11 0:01am    
learn from the best programmer ^_^ (codeproject asp.net masters ^_^)
but still need to learn a lot ^_^
Hi,

Try this:

function keyUp() {
        var mealallowance2 = $get('<%= txtmealallowance2.ClientID %>').value;
        var transportationallowance2 = $get('<%= txttransportationallowance2.ClientID %>').value;
        var perDiem2 =  $get('<%= txtPerDiem2.ClientID %>').value;
        var accomodation2 = $get('<%= txtaccomodation2.ClientID %>').value;
        var consultant2 = $get('<%= txtconsultant2.ClientID %>').value;
        var material2 = $get('<%= txtmaterial2.ClientID %>').value;
        // Your condition goes here...
        if (material2 == '')
        {
             $get('<%= txtTE2.ClientID %>').value = '';
        }
        else
        {
            $get('<%= txtTE2.ClientID %>').value =
            (mealallowance2 + transportationallowance2 +  perDiem2  +
            accomodation2 + consultant2 + material2);
        }
   }


Hope this could help...

Please remember to mark the replies as answers if they help and unmark them if they provide no help.

Regards,

Algem
 
Share this answer
 
Comments
walterhevedeich 27-Jul-11 23:27pm    
5 for the effort.
Asish Limbu 28-Jul-11 0:26am    
Perfect Answer.+5.

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