在运行时将文本框的值相乘 [英] multiplication of values of textboxs at runtime

查看:63
本文介绍了在运行时将文本框的值相乘的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在中继器中有文本框RateInNumbersTB并标记了LbQuantity,我希望将这些项目的值乘以b并乘以&;在运行时在其他文本框TotalAmountTB中显示结果,而无需任何回发.

i have textbox RateInNumbersTB and label LbQuantity in a repeater,i want the values of these items to b multiplied & display result in other textbox TotalAmountTB at runtime without any postback.

<script language="javascript" type="text/javascript">
function calc(obj,cal)
{
 var tot;
 var objid=obj.id.substring(0,obj.id.lastIndexOf(''_'')+1);
 tot=document.getElementById(objid + "LbQuantity");
 var total= document.getElementById (objid + "TotalAmountTB");
 total.value= obj.value * tot.value;
}
</script>


<asp:Repeater ID="Repeater1" runat="server" EnableTheming="true">
 <itemtemplate>
  <tr>
   <td><asp:Label ID="LbSNo" runat="server" Text=''<%# Bind("SNo")%>'' Width="25px"></td>
   <td><asp:Label ID="LbItem" runat="server" Text=''<%# Bind("Item")%>'' Width="75"></td>
   <td><asp:Label ID="LbDescription" runat="server" Text=''<%# Bind("Description")%>'' Width="75"></td>
   <td><asp:Label ID="LbUnit" runat="server" Text=''<%# Bind("Unit")%>'' Width="25"></td>
   <td><asp:Label ID="LbQuantity" runat="server" Text=''<%# Bind("Quantity")%>'' Width="30"></td>
   <td>
       <asp:TextBox ID="RateInNumbersTB" runat="server" onkeyup="calc(this,document.getElementById(''Repeater1''));" Width="90px">
       <asp:TextBox ID="RateInFigures" runat="server" Width="260px">
   </td>
   <td><asp:TextBox ID="TotalAmountTB" runat="server" Width="100px"></td>
 </tr>
 </itemtemplate>

推荐答案

首先,我不清楚您为什么尝试在此处进行操作:
为什么这样做:onkeyup="calc(this,document.getElementById(''Repeater1''));"

其次,您是否尝试调试?根据您说的话,很明显obj.valuetot.value都不是数字,因此当您尝试将其相乘时会出现NaN(不是数字错误)


现在,可能是两种情况:
1. tot形成的JavaScript对象不正确.
2. tot.value为空或不是数字.

使用调试器,然后查看问题出在哪里.如果不是调试器,则还可以使用警报"来查看对象的值.您所需要做的就是验证流程并纠正错误.

试试吧!
First of all I am not clear on why have you tried to do here:
Why this: onkeyup="calc(this,document.getElementById(''Repeater1''));"

Second, did you try to DEBUG? based on what you say, it''s clear that either obj.value OR tot.value is not a number and hence when you try to multiply it you get a NaN (Not a Number error)


Now, it might be two case:
1. tot Javascript object formed is not correct.
2. tot.value is empty or not a number.

Use Debugger, and see where the issue lies. If not debugger, you can also use ''alert'' to see the values of the object. All you need is to verify the flow and correct whats wrong.

Try!


这篇关于在运行时将文本框的值相乘的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆