function RPTcalculateCost()
{
var a = document.getElementById("ctl00$ContentPlaceHolder1$IR$ctl00$rptJobDetails$ctl01$txtRate");
var b = document.getElementById("ctl00$ContentPlaceHolder1$IR$ctl00$rptJobDetails$ctl02$txtHours");
var c = document.getElementById("ctl00$ContentPlaceHolder1$IR$ctl00$rptJobDetails$ctl02$txtCost");
if (b.value == '')
{
c.value = 0;
}
else
{
c.value = parseFloat(a.value) * parseFloat(b.value);
}
}
<td colspan="2" style="height: 19px">
<asp:Panel runat="server" ID="pnlJobDetails" DefaultButton="btnHidSave">
<asp:Repeater ID="rptJobDetails" runat="server">
<HeaderTemplate>
<table class="CostBox" width="100%">
<tr>
<td align="left" style="width: 80px; height: 24px"> Staff</td>
<td align="left" style="width: 95px; height: 24px">Staff type</td>
<td align="left" style="width: 55px; height: 24px">Hourly rate</td>
<td align="left" style="width: 35px; height: 24px">Available hours</td>
<td align="left" style="width: 85px; height: 24px">Cost</td>
<td style="height: 24px" > </td>
</tr>
<tr><td colspan="6"></td></tr>
</table>
<div style="height: 200px; overflow: auto;">
<table class="text" width="100%">
</HeaderTemplate>
<ItemTemplate>
<tr>
<td>
<table cellpadding="0" cellspacing="0">
<tr><td>
<div class="os" style="width:80px;overflow:hidden;border-right:1px solid gray">
<asp:DropDownList runat="server" ID="ddlStaff" Enabled="false" Font-Size="XX-Small" Width="180px"></asp:DropDownList>
</div></td>
</tr></table>
</td>
<td>
<table cellpadding="0" cellspacing="0">
<tr><td>
<div class="os" style="width:80px;overflow:hidden;border-right:1px solid gray">
<asp:DropDownList runat="server" ID="ddlStaffType2" Font-Size="XX-Small" Width="230px" AutoPostBack="true"></asp:DropDownList>
</div></td>
<td><img src="../images/arrow.jpg" /></td></tr></table>
</td>
<td><asp:TextBox runat="server" CssClass="costbox" ID="txtRate" Width="55px" Font-Size="XX-Small" OnKeyUp="javascript:RPTcalculateCost();" Text= <%# DataBinder.Eval(Container.DataItem, "HourlyRate")%>></asp:TextBox></td>
<td><asp:TextBox runat="server" CssClass="textbox2" ID="txtHours" Width="35px" Font-Size="XX-Small" OnKeyUp="javascript:RPTcalculateCost();" Text= <%# DataBinder.Eval(Container.DataItem, "AvailableHours")%> ></asp:TextBox></td>
<td><asp:TextBox runat="server" CssClass="costbox" ID="txtCost" Width="75px" Font-Size="XX-Small" Text= <%# DataBinder.Eval(Container.DataItem, "Cost")%> ></asp:TextBox></td>
<td><asp:TextBox runat="server" CssClass="textbox2" ID="intCount" Visible="false" Width="1px" Font-Size="XX-Small" Text= <%# DataBinder.Eval(Container.DataItem, "interventionCount")%> ></asp:TextBox></td>
<td><asp:Button runat="server" ID="btnDelete" Width="18px" Height="18px" CssClass="button" Text="X" ForeColor=red Font-Bold=true CommandArgument= <%# DataBinder.Eval(Container.DataItem, "ID") %> /></td>
<td><asp:Button runat="server" ID="btnSave" Height="18px" Width="28px" CssClass="button" Text="Save" Font-Size="10px" ToolTip="Save changes" ForeColor="green" Font-Bold="true" CommandArgument= <%# DataBinder.Eval(Container.DataItem, "ID") %> CommandName="save" /></td>
<td><asp:Button runat="server" ID="btnPrintDetail" Width="18px" Height="18px" CssClass="button" Text="?" ForeColor=DarkBlue Font-Bold=true ToolTip="Print details" CommandArgument= <%# DataBinder.Eval(Container.DataItem, "ID") %> CommandName="print" BackColor="LightBlue" Font-Names="Tahoma" /></td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table></div>
</FooterTemplate>
</asp:Repeater>
</asp:Panel>
ASKER
ASKER
<div id='divcost'>
<td><asp:TextBox runat="server" CssClass="costbox" ID="txtRate" Width="55px" Font-Size="XX-Small" OnKeyUp="javascript:RPTcalculateCost();" Text= <%# DataBinder.Eval(Container.DataItem, "HourlyRate")%>></asp:TextBox></td>
<td><asp:TextBox runat="server" CssClass="textbox2" ID="txtHours" Width="35px" Font-Size="XX-Small" OnKeyUp="javascript:RPTcalculateCost();" Text= <%# DataBinder.Eval(Container.DataItem, "AvailableHours")%> ></asp:TextBox></td>
<td><asp:TextBox runat="server" CssClass="costbox" ID="txtCost" Width="75px" Font-Size="XX-Small" Text= <%# DataBinder.Eval(Container.DataItem, "Cost")%> ></asp:TextBox></td>
</div>
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
function RPTcalculateCost()
{
var inputElements = divcost.getElementsByTagName('input');
for (var i = 0 ; i < inputElements.length ; i++)
{
var myElement = inputElements[i];
if (myElement.name !='txtCost')
{
myElement.value = parseFloat(myElement.name.indexOf('txtHours').value) * parseFloat(myElement.name.indexOf('txtRate').value);
}
}
}
ASKER
var inputElementRate = divcost.getElementsByTagName('txtRate');
var inputElementHours = divcost.getElementsByTagName('txtHours');
ASKER
function RPTcalculateCost()
{
var Rate = divcost.getElementsByTagName('txtRate');
var Hours = divcost.getElementsByTagName('txtHours');
var Cost = divcost.getElementsByTagName('txtCost');
Cost.value = parseFloat(Rate.value) * parseFloat(Hours.value);
}
#####################################################################
<asp:Panel runat="server" ID="pnlJobDetails" DefaultButton="btnHidSave">
<asp:Repeater ID="rptJobDetails" runat="server">
<HeaderTemplate>
<table class="CostBox" width="100%">
<tr>
<td align="left" style="width: 80px; height: 24px"> Staff</td>
<td align="left" style="width: 95px; height: 24px">Staff type</td>
<td align="left" style="width: 55px; height: 24px">Hourly rate</td>
<td align="left" style="width: 35px; height: 24px">Available hours</td>
<td align="left" style="width: 85px; height: 24px">Cost</td>
<td style="height: 24px" > </td>
</tr>
<tr><td colspan="6"></td></tr>
</table>
<div style="height: 200px; overflow: auto;">
<table class="text" width="100%">
</HeaderTemplate>
<ItemTemplate>
<tr>
<td>
<table cellpadding="0" cellspacing="0">
<tr><td>
<div class="os" style="width:80px;overflow:hidden;border-right:1px solid gray">
<asp:DropDownList runat="server" ID="ddlStaff" Enabled="false" Font-Size="XX-Small" Width="180px"></asp:DropDownList>
</div></td>
</tr></table>
</td>
<td>
<table cellpadding="0" cellspacing="0">
<tr><td>
<div class="os" style="width:80px;overflow:hidden;border-right:1px solid gray">
<asp:DropDownList runat="server" ID="ddlStaffType2" Font-Size="XX-Small" Width="230px" AutoPostBack="true"></asp:DropDownList>
</div></td>
<td><img src="../images/arrow.jpg" /></td></tr></table>
</td>
<div id='divcost'>
<td><asp:TextBox runat="server" CssClass="costbox" ID="txtRate" Width="55px" Font-Size="XX-Small" OnKeyUp="javascript:RPTcalculateCost();" Text= <%# DataBinder.Eval(Container.DataItem, "HourlyRate")%>></asp:TextBox></td>
<td><asp:TextBox runat="server" CssClass="textbox2" ID="txtHours" Width="35px" Font-Size="XX-Small" OnKeyUp="javascript:RPTcalculateCost();" Text= <%# DataBinder.Eval(Container.DataItem, "AvailableHours")%> ></asp:TextBox></td>
<td><asp:TextBox runat="server" CssClass="costbox" ID="txtCost" Width="75px" Font-Size="XX-Small" Text= <%# DataBinder.Eval(Container.DataItem, "Cost")%> ></asp:TextBox></td>
</div>
<td><asp:TextBox runat="server" CssClass="textbox2" ID="intCount" Visible="false" Width="1px" Font-Size="XX-Small" Text= <%# DataBinder.Eval(Container.DataItem, "interventionCount")%> ></asp:TextBox></td>
<td><asp:Button runat="server" ID="btnDelete" Width="18px" Height="18px" CssClass="button" Text="X" ForeColor=red Font-Bold=true CommandArgument= <%# DataBinder.Eval(Container.DataItem, "ID") %> /></td>
<td><asp:Button runat="server" ID="btnSave" Height="18px" Width="28px" CssClass="button" Text="Save" Font-Size="10px" ToolTip="Save changes" ForeColor="green" Font-Bold="true" CommandArgument= <%# DataBinder.Eval(Container.DataItem, "ID") %> CommandName="save" /></td>
<td><asp:Button runat="server" ID="btnPrintDetail" Width="18px" Height="18px" CssClass="button" Text="?" ForeColor=DarkBlue Font-Bold=true ToolTip="Print details" CommandArgument= <%# DataBinder.Eval(Container.DataItem, "ID") %> CommandName="print" BackColor="LightBlue" Font-Names="Tahoma" /></td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table></div>
</FooterTemplate>
</asp:Repeater>
</asp:Panel>
ASKER
function RPTcalculateCost()
{
var parentDiv = document.getElementById("divcost");
var Rate = parentDiv.getElementById('txtRate');
var Hours = parentDiv.getElementsByTagName('txtHours');
var Cost = parentDiv.getElementsByTagName('txtCost');
Cost.value = parseFloat(Rate.value) * parseFloat(Hours.value);
}
function RPTcalculateCost()
{
var Rate = document.getElementById('txtRate');
var Hours = document.getElementsByTagName('txtHours');
var Cost = document.getElementsByTagName('txtCost');
Cost.value = parseFloat(Rate.value) * parseFloat(Hours.value);
}
ASKER
ASKER
<td><asp:TextBox runat="server" ID="txtRate" Width="55px" Font-Size="XX-Small" OnKeyDown="javascript:RPTcalculateCost();" Text= "20"></asp:TextBox></td>
<td><asp:TextBox runat="server" ID="txtHours" Width="35px" Font-Size="XX-Small" OnKeyDown="javascript:RPTcalculateCost();" Text="10" ></asp:TextBox></td>
<td><asp:TextBox runat="server" ID="txtCost" Width="75px" Font-Size="XX-Small" Text= "" ></asp:TextBox></td>
**********************************************************************
<script type="text/javascript">
function RPTcalculateCost()
{
document.getElementById('txtCost').value =document.getElementById('txtRate').value * document.getElementById('txtHours').value;
}
</script>
ASKER
<asp:Panel runat="server" ID="pnlJobDetails" DefaultButton="btnHidSave">
<asp:Repeater ID="rptJobDetails" runat="server">
<HeaderTemplate>
<table class="CostBox" width="100%">
<tr>
<td align="left" style="width: 80px; height: 24px"> Staff</td>
<td align="left" style="width: 95px; height: 24px">Staff type</td>
<td align="left" style="width: 55px; height: 24px">Hourly rate</td>
<td align="left" style="width: 35px; height: 24px">Available hours</td>
<td align="left" style="width: 85px; height: 24px">Cost</td>
<td style="height: 24px" > </td>
</tr>
<tr><td colspan="6"></td></tr>
</table>
<div style="height: 200px; overflow: auto;">
<table class="text" width="100%">
</HeaderTemplate>
<ItemTemplate>
<tr>
<td>
<table cellpadding="0" cellspacing="0">
<tr><td>
<div class="os" style="width:80px;overflow:hidden;border-right:1px solid gray">
<asp:DropDownList runat="server" ID="ddlStaff" Enabled="false" Font-Size="XX-Small" Width="180px"></asp:DropDownList>
</div></td>
</tr></table>
</td>
<td>
<table cellpadding="0" cellspacing="0">
<tr><td>
<div class="os" style="width:80px;overflow:hidden;border-right:1px solid gray">
<asp:DropDownList runat="server" ID="ddlStaffType2" Font-Size="XX-Small" Width="230px" AutoPostBack="true"></asp:DropDownList>
</div></td>
<td><img src="../images/arrow.jpg" /></td></tr></table>
</td>
<div id='divcost'>
<td><asp:TextBox runat="server" CssClass="costbox" ID="txtRate" Width="55px" Font-Size="XX-Small" OnKeyUp="javascript:RPTcalculateCost();" Text= <%# DataBinder.Eval(Container.DataItem, "HourlyRate")%>></asp:TextBox></td>
<td><asp:TextBox runat="server" CssClass="textbox2" ID="txtHours" Width="35px" Font-Size="XX-Small" OnKeyUp="javascript:RPTcalculateCost();" Text= <%# DataBinder.Eval(Container.DataItem, "AvailableHours")%> ></asp:TextBox></td>
<td><asp:TextBox runat="server" CssClass="costbox" ID="txtCost" Width="75px" Font-Size="XX-Small" Text= <%# DataBinder.Eval(Container.DataItem, "Cost")%> ></asp:TextBox></td>
</div>
<td><asp:TextBox runat="server" CssClass="textbox2" ID="intCount" Visible="false" Width="1px" Font-Size="XX-Small" Text= <%# DataBinder.Eval(Container.DataItem, "interventionCount")%> ></asp:TextBox></td>
<td><asp:Button runat="server" ID="btnDelete" Width="18px" Height="18px" CssClass="button" Text="X" ForeColor=red Font-Bold=true CommandArgument= <%# DataBinder.Eval(Container.DataItem, "ID") %> /></td>
<td><asp:Button runat="server" ID="btnSave" Height="18px" Width="28px" CssClass="button" Text="Save" Font-Size="10px" ToolTip="Save changes" ForeColor="green" Font-Bold="true" CommandArgument= <%# DataBinder.Eval(Container.DataItem, "ID") %> CommandName="save" /></td>
<td><asp:Button runat="server" ID="btnPrintDetail" Width="18px" Height="18px" CssClass="button" Text="?" ForeColor=DarkBlue Font-Bold=true ToolTip="Print details" CommandArgument= <%# DataBinder.Eval(Container.DataItem, "ID") %> CommandName="print" BackColor="LightBlue" Font-Names="Tahoma" /></td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table></div>
</FooterTemplate>
</asp:Repeater>
</asp:Panel>
ASKER
function RPTcalculateCost()
{
document.getElementById('txtCost').value =document.getElementById('txtRate').value * document.getElementById('txtHours').value;
}
#######################################################################
<asp:Panel runat="server" ID="pnlJobDetails" DefaultButton="btnHidSave">
<asp:Repeater ID="rptJobDetails" runat="server">
<HeaderTemplate>
<table class="CostBox" width="100%">
<tr>
<td align="left" style="width: 80px; height: 24px"> Staff</td>
<td align="left" style="width: 95px; height: 24px">Staff type</td>
<td align="left" style="width: 55px; height: 24px">Hourly rate</td>
<td align="left" style="width: 35px; height: 24px">Available hours</td>
<td align="left" style="width: 85px; height: 24px">Cost</td>
<td style="height: 24px" > </td>
</tr>
<tr><td colspan="6"></td></tr>
</table>
<div style="height: 200px; overflow: auto;">
<table class="text" width="100%">
</HeaderTemplate>
<ItemTemplate>
<tr>
<td>
<table cellpadding="0" cellspacing="0">
<tr><td>
<div class="os" style="width:80px;overflow:hidden;border-right:1px solid gray">
<asp:DropDownList runat="server" ID="ddlStaff" Enabled="false" Font-Size="XX-Small" Width="180px"></asp:DropDownList>
</div></td>
</tr></table>
</td>
<td>
<table cellpadding="0" cellspacing="0">
<tr><td>
<div class="os" style="width:80px;overflow:hidden;border-right:1px solid gray">
<asp:DropDownList runat="server" ID="ddlStaffType2" Font-Size="XX-Small" Width="230px" AutoPostBack="true"></asp:DropDownList>
</div></td>
<td><img src="../images/arrow.jpg" /></td></tr></table>
</td>
<td><asp:TextBox runat="server" CssClass="costbox" ID="txtRate" Width="55px" Font-Size="XX-Small" OnKeyDown="javascript:RPTcalculateCost();" Text= <%# DataBinder.Eval(Container.DataItem, "HourlyRate")%>></asp:TextBox></td>
<td><asp:TextBox runat="server" CssClass="textbox2" ID="txtHours" Width="35px" Font-Size="XX-Small" OnKeyDown="javascript:RPTcalculateCost();" Text= <%# DataBinder.Eval(Container.DataItem, "AvailableHours")%> ></asp:TextBox></td>
<td><asp:TextBox runat="server" CssClass="costbox" ID="txtCost" Width="75px" Font-Size="XX-Small" Text= <%# DataBinder.Eval(Container.DataItem, "Cost")%> ></asp:TextBox></td>
<td><asp:TextBox runat="server" CssClass="textbox2" ID="intCount" Visible="false" Width="1px" Font-Size="XX-Small" Text= <%# DataBinder.Eval(Container.DataItem, "interventionCount")%> ></asp:TextBox></td>
<td><asp:Button runat="server" ID="btnDelete" Width="18px" Height="18px" CssClass="button" Text="X" ForeColor=red Font-Bold=true CommandArgument= <%# DataBinder.Eval(Container.DataItem, "ID") %> /></td>
<td><asp:Button runat="server" ID="btnSave" Height="18px" Width="28px" CssClass="button" Text="Save" Font-Size="10px" ToolTip="Save changes" ForeColor="green" Font-Bold="true" CommandArgument= <%# DataBinder.Eval(Container.DataItem, "ID") %> CommandName="save" /></td>
<td><asp:Button runat="server" ID="btnPrintDetail" Width="18px" Height="18px" CssClass="button" Text="?" ForeColor=DarkBlue Font-Bold=true ToolTip="Print details" CommandArgument= <%# DataBinder.Eval(Container.DataItem, "ID") %> CommandName="print" BackColor="LightBlue" Font-Names="Tahoma" /></td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table></div>
</FooterTemplate>
</asp:Repeater>
</asp:Panel>
ASKER
function RPTcalculateCost(){
if (isUnsignedInteger(document.getElementById('txtRate').value )< 0)
{
document.getElementById('txtCost').value = 0 * document.getElementById('txtHours').value;
}
else if(isUnsignedInteger(document.getElementById('txtHours').value )< 0)
{
document.getElementById('txtCost').value = 0 * document.getElementById('txtRate').value;
}
else
{
document.getElementById('txtCost').value = document.getElementById('txtRate').value * document.getElementById('txtHours').value;
}
}
function isUnsignedInteger(s) {
return (s.toString().search(/^[0-9]+$/) == 0);
}
ASKER
ASKER
ASKER
function RPTcalculateCost(a,b,c,btnSave) //see rptJobDetails_ItemBound
{
var Rate = document.getElementById(a);
var Hours = document.getElementById(b);
var Cost = document.getElementById(c);
document.getElementById(btnSave).style.backgroundColor = 'Light Blue';
if (Hours.value == '' || Rate.value == '')
{
Cost.value = 0;
}
else
{
Cost.value = parseFloat(Rate.value) * parseFloat(Hours.value);
}
}
#############################################################################
<asp:Repeater ID="rptJobDetails" runat="server">
<HeaderTemplate>
<div style="height: 200px; overflow: auto;">
<table class="text" width="100%">
</HeaderTemplate>
<ItemTemplate>
<tr>
<td><asp:TextBox runat="server" CssClass="costbox" ID="txtRate" Width="55px" Font-Size="XX-Small" Text= <%# DataBinder.Eval(Container.DataItem, "HourlyRate")%>></asp:TextBox></td>
<td><asp:TextBox runat="server" CssClass="textbox2" ID="txtHours" Width="35px" Font-Size="XX-Small" Text= <%# DataBinder.Eval(Container.DataItem, "AvailableHours")%> ></asp:TextBox></td>
<td><asp:TextBox runat="server" CssClass="costbox" ID="txtCost" Width="75px" Font-Size="XX-Small" Text= <%# DataBinder.Eval(Container.DataItem, "Cost")%> ></asp:TextBox></td>
</tr>
</ItemTemplate>
</asp:Repeater>
################################################################################
Private Sub rptJobDetails_ItemBound(ByVal sender As Object, ByVal e As RepeaterItemEventArgs) Handles rptJobDetails.ItemDataBound
Try
If e.Item.ItemType = ListItemType.AlternatingItem Or e.Item.ItemType = ListItemType.Item Then
Dim txtRate As TextBox = CType(e.Item.FindControl("txtRate"), TextBox)
Dim txtHours As TextBox = CType(e.Item.FindControl("txtHours"), TextBox)
Dim txtCost As TextBox = CType(e.Item.FindControl("txtCost"), TextBox)
txtRate.Attributes("onchange") = "RPTcalculateCost('" + txtRate.ClientID + "'" + ",'" + txtHours.ClientID + "','" + txtCost.ClientID + "','" + btnSave.ClientID + "');"
txtHours.Attributes("onchange") = "RPTcalculateCost('" + txtRate.ClientID + "'" + ",'" + txtHours.ClientID + "','" + txtCost.ClientID + "');"
Catch ex As Exception
cvError.IsValid = False
cvError.Text = ex.Message
End Try
End Sub
ASKER
The .NET Framework is not specific to any one programming language; rather, it includes a library of functions that allows developers to rapidly build applications. Several supported languages include C#, VB.NET, C++ or ASP.NET.
TRUSTED BY
Now what you can do is, write javascript for the change event for each textbox,
use the variable 'this' in javascript which gives reference to that particular textbox.
Also Put all 1,2 and 3 in a div. So that when you can get all your textbox references from the div using getelement by tagname with input tag . I hope you understood it.
Only concern you'll have is how to get the div tag, which u can get from 'this' object's parent which will be div as you are going to place 1,2 and 3 in the div.
I hope I made it almost clear. Let me know if its not. Ofcourse you'll have to write a small complicated looking script, but that's the fun part of it :P