calculation with validation

Mar 8 2010 2:16 AM

function Sum()


var txtVal1= document.getElementById('<%= txtVal1.ClientID %>').value;
var txtVal2 = document.getElementById('<%= txtVal2.ClientID %>').value;

if(txtVal1.toString().replace(/_/g,' ').trim().length==0)
{
txtVal1="0";
}

if(txtVal2.toString().replace(/_/g,' ').trim().length==0)
{
txtVal2="0";
}

var result= parseFloat(txtVal1) + parseFloat(txtVal2);
document.getElementById('<%= txtAnswer.ClientID %>').value= result ;

}
hi,,,i made one javascript as given above to calculate the value of 2 textbox and give answer in 3rd textbox ,,if i dont apply any value in a textbox it will automatcally consider value with zero..but its not working,,,give me some idea..with code,,thnx


Answers (1)