Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   ASP .Net (http://www.velocityreviews.com/forums/f29-asp-net.html)
-   -   Client-side calculation without postback (http://www.velocityreviews.com/forums/t100264-client-side-calculation-without-postback.html)

John Mason 04-09-2005 01:07 AM

Client-side calculation without postback
 
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.





*** Sent via Developersdex http://www.developersdex.com ***

Teemu Keiski 04-09-2005 09:27 AM

Re: Client-side calculation without postback
 
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.

--
Teemu Keiski
ASP.NET MVP, AspInsider
Finland, EU

"John Mason" <wollondilly@hotmail.com> wrote in message
news:usmq7BKPFHA.2788@TK2MSFTNGP09.phx.gbl...
> 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.
>
>
>
>
>
> *** Sent via Developersdex http://www.developersdex.com ***





All times are GMT. The time now is 11:40 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.