Client-side calculation without postback

J

John Mason

Hi,

I am trying to figure out how to do a client-side calculation based on
textbox values, using asp.net, without performing a postback.

I have 2 textboxes...

<asp:textbox runat="server" CssClass="ddclass" ID="txtTotal"
onBlur="calculate()" />

<asp:textbox runat="server" CssClass="ddclass" ID="txtAmount" />


I have used the following Javascript code...

<SCRIPT TYPE="text/javascript">
<!--
function calculate() {
var Amount;
Amount = (document.forms["_ctl0"].elements[5].value * 0.075);
Amount = CovCom.toFixed(2);
document.forms["_ctl0"].elements[6].value = Amount;

};
-->
</script>

However, sometimes the element number changes, and calculation does not
occur. Is there a way of referring to the textbox ID's in the Javscript
code?

Has anyone performed client-side calculations in asp.net without
postback? Is there a better way than doing the above?

Appreciate any help!!

Thanks,

John.
 
T

Teemu Keiski

Hi,

you can out the the generated ID from code by using txtTotal.ClientID
property of the control and outputting it to the script (either generate
entire script block in code or append tthe id using <%=txtTotal.ClientID%>
block in middle of the script.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,191
Latest member
BuyKetoBeez

Latest Threads

Top