Auto Multiply Two Column In Gridview
HI, I need to calculate values of two textboxex in gridview and display the result in the third textbox using javascript as soon as the value entered in second textbox. my textbox
Solution 1:
you should change string to int (as value of any textbox returns string) before multiplication :)
try this :-
txt1.Attributes["onKeyup"] = "javascript: return multiplication('" + Convert.ToInt32(txt1.Text) + "','" + Convert.ToInt32(txt2.Text) + "','" + Convert.ToInt32(txt3.ClientID) + "')";
txt2.Attributes["onKeyup"] = "javascript: return multiplication('" + Convert.ToInt32(txt1.Text) + "','" + Convert.ToInt32(txt2.Text) + "','" + Convert.ToInt32(txt3.ClientID) + "')";
In script :-
<Scripttype="text/javascript">functionmultiplication(Qty,Rate,txt3)
{
//Your logic for multiplicationdocument.getElementById(txt3).value=Qty*Rate;
}
</script>
Solution 2:
The problem is with these lines of code
txt1.Attributes["onKeyup"] = "javascript: return multiplication('" + txt1.ClientID + "','" + txt2.ClientID + "','" + txt3.ClientID + "')";
txt2.Attributes["onKeyup"] = "javascript: return multiplication('" + txt1.ClientID + "','" + txt2.ClientID + "','" + txt3.ClientID + "')";
Use Add method instead
txt1.Attributes.Add("onKeyup", "javascript: return multiplication('" +
txt1.ClientID + "','" + txt2.ClientID + "','" + txt3.ClientID + "')");
txt2.Attributes.Add("onKeyup", "javascript: return multiplication('" +
txt1.ClientID + "','" + txt2.ClientID + "','" + txt3.ClientID + "')");
and also do parseInt()
in javascript
varQty = parseInt(document.getElementById(txt1).value);
varRate = parseInt(document.getElementById(txt2).value);
Post a Comment for "Auto Multiply Two Column In Gridview"