Click here to Skip to main content
15,890,123 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
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
Posted
Updated 18-May-10 20:02pm
v3

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
 
Share this answer
 
Comments
shanawazway 19-May-10 4:07am    
I tried this , it is OK with normal page, but when I tried in child master page, it is not detecting the TEXT control.
It is saying Object required. It means it is not finding any Text control.
What could be the problem?

Please help me once again
Thanx
Nikunj Pandav 20-Jul-16 5:16am    
<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;

with
a1=document.getElementById("<=txtAmount1.ClientID>").value;
Nikunj Pandav 20-Jul-16 5:16am    
<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;

with
a1=document.getElementById("<=txtAmount1.ClientID>").value;
Gavs43 20-May-10 6:00am    
Are you checking the source of the rendered page to make sure the two client id's match?
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......
 
Share this answer
 
Comments
shanawazway 19-May-10 4:11am    
dear swati,
below statement is not working in child master page.
What could be the reason and the solution.

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

Thanx
Shahnawaz
Your syntax for code is wrong.

In place of this

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

use following code

a1=document.getElementById("<%=txtAmount1.ClientId%>").value;
 
Share this answer
 
v2
Comments
Sandeep Mewara 20-May-10 2:25am    
Reason for my vote of 1
It's the same as answer1.
Gavs43 20-May-10 5:56am    
it's not the same as answer 1, the syntax is correct on this one, look out for missing %'s on answer1
Nikunj Pandav 20-Jul-16 5:19am    
ohhhhh tnx mitrooo
Moz aavi gai hooo Ha Ha Ha

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900