Client-side calculation without postback

Discussion in 'ASP .Net' started by John Mason, Apr 9, 2005.

  1. John Mason

    John Mason Guest

    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 ***
     
    John Mason, Apr 9, 2005
    #1
    1. Advertising

  2. John Mason

    Teemu Keiski Guest

    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" <> wrote in message
    news:...
    > 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, Apr 9, 2005
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. amirmi
    Replies:
    0
    Views:
    825
    amirmi
    Aug 1, 2006
  2. amirmi
    Replies:
    1
    Views:
    668
    nataliepea
    Sep 8, 2006
  3. amirmi
    Replies:
    0
    Views:
    627
    amirmi
    Aug 1, 2006
  4. Boss302
    Replies:
    0
    Views:
    1,069
    Boss302
    Nov 21, 2006
  5. Jim Huskey
    Replies:
    1
    Views:
    121
    Michael Baltic
    Jun 29, 2005
Loading...

Share This Page