Sunday, May 19, 2024
 Popular · Latest · Hot · Upcoming
71
rated 0 times [  75] [ 4]  / answers: 1 / hits: 57389  / 12 Years ago, thu, august 23, 2012, 12:00:00

Hi all i am writing calculation of varius asp textbox controls. I want my calculation being done with keypress event. Below code i am using but not working



.aspx page



<asp:TextBox ID=txtMaintCost onkeypress=calculateFinanceDetail(); return false; runat=server></asp:TextBox>


.js file



function calculateFinanceDetail() {
var txtMaintCost = $('input[id$=txtMaintCost]').val();
var txtInstallCost = $('input[id$=txtInstallCost]').val();
var txtFreightCost = $('input[id$=txtFreightCost]').val();
}


its not calling javascript function on keypress event...
If anyone have any idea than please help me in this..


More From » jquery

 Answers
33

Missing at the end of id of textbox.



Change



<asp:TextBox ID=txtMaintCost onkeypress=calculateFinanceDetail(); return false; runat=server></asp:TextBox>


To



<asp:TextBox ID=txtMaintCost onkeypress=calculateFinanceDetail(); return false; runat=server></asp:TextBox>


Try using the ClientID of server controls. You might not having static ids for server side controls. You do not have to use wild cards if you have fixed ids.



function calculateFinanceDetail() {
var txtMaintCost = $('input[id=<%=txtMaintCost.ClientID%>]').val();
var txtInstallCost = $('input[id=<%=txtInstallCost.ClientID%>]').val();
var txtFreightCost = $('input[id=<%=txtFreightCost.ClientID%>]').val();
}

[#83462] Wednesday, August 22, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
albert

Total Points: 652
Total Questions: 105
Total Answers: 108

Location: Pitcairn Islands
Member since Fri, Oct 15, 2021
3 Years ago
;