在"onkeyup"上使用JavaScript计算ASP:TextBox的总和.事件 [英] Calculate sum of ASP:TextBox using JavaScript on "onkeyup" Event

查看:123
本文介绍了在"onkeyup"上使用JavaScript计算ASP:TextBox的总和.事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

适用于是否有人可以解决我的以下查询:
我尝试了这段Javascript代码,但它说调用脚本方法"calc"所需的对象是:confused:.但是对象存在于此.


< asp:textbox id ="txtAmount4" xmlns:asp =#unknown"> onkeyup ="calc():( ;"
runat ="server" Width ="56px" Height ="13px">
____________________________________________________________________


无效函数calc(dat){
var a1,a2,a3,a4,a5,total,pp;


//在a1变量中获取"txtAmount1"的值时会给出错误.
//与a1,a2,a3,a4,a5相同

a1 = document.getElementById(<%=''txtAmount1''%>).value;
a2 = document.getElementById(<%=''txtAmount2''%>).value;
a3 = document.getElementById(<%=''txtAmount3''%>).value;
a4 = document.getElementById(<%=''txtAmount4''%>).value;
a5 = document.getElementById(<%=''txtAmount5''%>).value;


total = parseInt(a1)+ parseInt(a2)+ parseInt(a3)+ parseInt(a4)+ parseInt(a5);

document.getElementById(<%=''txtPaymentAmount''%>).value = total;

}



谢谢
Shahnawaz

Appriciate if anyone can solve my below query:
I tried this Javascript code but it say object required on calling the script method "calc":confused:.But object is exist there.


<asp:textbox id="txtAmount4" xmlns:asp="#unknown">onkeyup="calc() :( ;"
runat="server" Width="56px" Height="13px">
____________________________________________________________________


void function calc(dat){
var a1,a2,a3,a4,a5,total,pp;


//It gives error while taking the value of "txtAmount1" in a1 variable.
//same for a1,a2,a3,a4,a5

a1=document.getElementById(<%=''txtAmount1''%>).value;
a2=document.getElementById(<%=''txtAmount2''%>).value;
a3=document.getElementById(<%=''txtAmount3''%>).value;
a4=document.getElementById(<%=''txtAmount4''%>).value;
a5=document.getElementById(<%=''txtAmount5''%>).value;


total=parseInt(a1)+parseInt(a2)+parseInt(a3)+parseInt(a4)+parseInt(a5);

document.getElementById(<%=''txtPaymentAmount''%>).value=total;

}



Thanx
Shahnawaz

推荐答案

首先,这是
First of all o this
<asp:textbox id="txtAmount4" xmlns:asp="#unknown" onkeyup="calc() ;"
runat="server" Width="56px" Height="13px">



然后替换
的每一行



then replace every line of

a1=document.getElementById(<%=''txtAmount1''%>).value;<br />






with

a1=document.getElementById("<=txtAmount1.ClientID>").value;<br />



尽情享受



enjoy it




您遇到错误bcoz,您无法使用getElementByID正确捕获文本框ID.
所以尝试一下......

var myTextField = document.getElementById(''txtAmount1'');
alert(myTextField.value);

并且您没有从调用函数传递任何参数,因为您在javascript中的calc函数中删除了一个参数.只需检查一下即可.

希望您能解决问题......
Hi,

U r getting error bcoz, u r not properly capturing the textbox id using getElementByID.
So try this.........

var myTextField = document.getElementById(''txtAmount1'');
alert(myTextField.value);

and u r not passing any parameter from calling function, as u declread a parameter in calc function in javascript. just check it.

hope u solve the problem......


您的代码语法错误.

代替此

a1=document.getElementById(<%=''txtAmount1''%>).value;

使用以下代码

a1=document.getElementById("<%=txtAmount1.ClientId%>").value;
Your syntax for code is wrong.

In place of this

a1=document.getElementById(<%=''txtAmount1''%>).value;

use following code

a1=document.getElementById("<%=txtAmount1.ClientId%>").value;


这篇关于在"onkeyup"上使用JavaScript计算ASP:TextBox的总和.事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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