Calculate Several Fields based on OnChange Event of a Textbox

P

pmarisole

I need to assign a percentage in a txtbox and update several other
fields with the onChange event(I quess), This is an Asp.Net page. I
am new to Javascript and can't figure out how to make this work.
Please help.

Here is the code in the Markup:
function Calc()
{
var form = document.form1;
var thisCellId = "";
if (rowId == "" || txtBoxId == "")
return false;

var dScore = parseFloat(getCellValue(rowId,4));
var dCurrentDol = parseFloat(getCellValue(rowId,7));
var dMaxDol = parseFloat(getCellValue(rowId,8));
var dPercentIncrease =
parseFloat(document.all(txtBoxId).value);
dPercentIncrease = dPercentIncrease / 100;
var dResult = dCurrentDol * dPercentIncrease;
var dCalcDol = Math.round(dCurrentDol + dResult);
if (dCalcDol > dMaxDol)
{
var dCurMax = (dCurrentDol - dMaxDol);
var dNewPct = (dCurMax / -dCurrentDol) * 100;
document.all(txtBoxId).value = dNewPct.toFixed(2);
}
var dRemaining = dMaxDol - dCalcDol
setCellValue(rowId,11,dRemaining);
if (dCalcDol > dMaxDol)
setCellValue(rowId,12,dMaxDol);
else
setCellValue(rowId,12,dCalcDol);

var dFinDol = parseFloat(getCellValue(rowId,
12));
var dMonthlyIncrease = dFinDol - dCurrentDol;
setCellValue(rowId,13,dMonthlyIncrease);

var dMaxLumpDol = dFinDol * 0.035 * 12;
setCellValue(rowId,14,Math.round(dMaxLumpDol));

var dAwardedLumpDol = 0.0;
if (dCurrentDol == dMaxDol)
dAwardedLumpDol = dMaxLumpDol;
else if (dFinalSal == dMaxDol)
{
dRemaining = (dRemaining * -12)
if (dMaxLumpDol > dRemaining)
dAwardedLumpDol = dRemaining;
else
dAwardedLumpDol = dMaxLumpDol
}
setCellValue(rowId,15,Math.round(dAwardedLumpDol));
var thisRowId = getGridRow(rowId).id;
var AwardedSum = parseFloat(getCellValue(rowId,15));
}
</script>

This is in the Code-Behind
Partial Class SPRTEST
Inherits System.Web.UI.Page
Dim LoggedInMgrCode As String = ""
Dim LoggedInLevel As Integer = 0
Dim ds As DataSet = Nothing
Dim dAccumTotal As Decimal
Dim dMgrAccumTotal As Decimal
Dim sFY As String = ""
Dim dTotalScores As Decimal
Dim dRangePercent As Decimal
Dim EType As String = ""
Dim iAccess As Integer = 0
Protected Sub GetData()
ds = New DataSet
ds = VPSpreadsheetAllocatedGet(LoggedInMgrCode, LoggedInLevel,
sFY)
If Not ds.Tables(0) Is Nothing Then
GridView1.DataSource = ds.Tables(0)
GridView1.DataBind()
For Each gvr As GridViewRow In GridView1.Rows
If gvr.RowType = DataControlRowType.DataRow Then
If gvr.Cells(6).Text = "0.00" Then
gvr.Cells(6).Text = ""
End If
Dim txtPI = CType(gvr.FindControl("txtPI"),
TextBox)
For i As Integer = 0 To gvr.Cells.Count - 1
gvr.Cells(i).Attributes.Add("id", "cell" &
gvr.RowIndex & i)
Next
End If
Next gvr
End If

End Sub

Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal
e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles
GridView1.RowDataBound
If e.Row.RowType = DataControlRowType.DataRow Then
(Textbox)e.Row.FindControl("txtPI").Attributes.Add("onChange",
"Calc(this)")
CType(e.Row.FindControl("txtPI"),
DataBoundControl).Attributes.Add("OnChange", "Calc(this)")
CType(e.Row.FindControl("Final Dollars"),
DataGrid).Attributes.Add("OnChange", "Calc()")
CType(e.Row.FindControl("Monthly Dollars"),
DataGrid).Attributes.Add("OnChange", "Calc()")
CType(e.Row.FindControl("Max Dollars"),
DataGrid).Attributes.Add("OnChange", "Calc()")
CType(e.Row.FindControl("Awarded Dollars"),
DataGrid).Attributes.Add("OnChange", "Calc()")
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top