How to build the Javascript Depend upon funtion

Last post 07-04-2009 7:34 AM by mudassarkhan. 4 replies.

Sort Posts:

  • How to build the Javascript Depend upon funtion

    07-04-2009, 5:18 AM
    • Member
      point Member
    • dilipmca04
    • Member since 04-23-2009, 8:22 AM
    • Posts 41

    i have the function like Textbox1 + TextBox2 * TextBox3 + (TextBox4 + TextBox5)/3  this one take as a formula ..and these formula i append to TextBox6 means these formula result i need to place on TextBox6..


    Same like i have so many formulas for ex :-TextBox4= TextBox1 + (TextBox2 + TextBox3)/3


    How can i write the Javascript to these type of formulas ..any one give examples..

  • Re: How to build the Javascript Depend upon funtion

    07-04-2009, 6:47 AM
    Answer

    var val1 = document.getElementById("TextBox1").value;
               var val2 = document.getElementById("TextBox2").value;
               var val3 = document.getElementById("TextBox3").value;
               var val4 = document.getElementById("TextBox4").value;
               var val5 = document.getElementById("TextBox5").value;
               document.getElementById("TextBox6").value = Val1 + Val2 * Val3 + (Val4 + Val5)/3;

    do like this for other also.

    Give a man a fish and you feed him for a day. Teach a man to fish and you feed him forever.
  • Re: How to build the Javascript Depend upon funtion

    07-04-2009, 7:10 AM
    Answer
    • All-Star
      59,913 point All-Star
    • mudassarkhan
    • Member since 02-28-2008, 5:28 AM
    • Mumbai, India
    • Posts 10,551
    • TrustedFriends-MVPs

     

    ramireddyindia:
  • var val1 = document.getElementById("TextBox1").value;   
  •            var val2 = document.getElementById("TextBox2").value;   
  •            var val3 = document.getElementById("TextBox3").value;   
  •            var val4 = document.getElementById("TextBox4").value;   
  •            var val5 = document.getElementById("TextBox5").value;   
  •            document.getElementById("TextBox6").value = Val1 + Val2 * Val3 + (Val4 + Val5)/3;
  • This will not work JavaScript is case sensitive

    val1 and Val1 are 2 different things

    The correct way of doing it

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head id="Head1" runat="server">
        <title>Untitled Page</title>
        <script type="text/javascript" language="javascript">
        function Calculate()
        {
               var val1 = parseInt(document.getElementById("<%=TextBox1.ClientID%>").value);
               var val2 = parseInt(document.getElementById("<%=TextBox2.ClientID%>").value);
               var val3 = parseInt(document.getElementById("<%=TextBox3.ClientID%>").value);
               var val4 = parseInt(document.getElementById("<%=TextBox4.ClientID%>").value);
               var val5 = parseInt(document.getElementById("<%=TextBox5.ClientID%>").value);
               document.getElementById("<%=TextBox6.ClientID%>").value = val1 + val2 * val3 + (val4 + val5)/3;
        }
      
        </script>
    </head>
    <body >
        <form id="form1" runat="server">
            <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
            <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
            <asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
            <asp:TextBox ID="TextBox4" runat="server"></asp:TextBox>
            <asp:TextBox ID="TextBox5" runat="server"></asp:TextBox>
            <asp:TextBox ID="TextBox6" runat="server"></asp:TextBox>
            <input id="Button1" type="button" value="Calculate"  onclick = "Calculate()" />
        </form>
    </body>
    </html>


     

  • Re: How to build the Javascript Depend upon funtion

    07-04-2009, 7:18 AM

    thanks mudassarkhan, I know javascript is case - sensitive.

    I didn't write it in editor. I just typed here and gave it.

    Give a man a fish and you feed him for a day. Teach a man to fish and you feed him forever.
  • Re: How to build the Javascript Depend upon funtion

    07-04-2009, 7:34 AM
    • All-Star
      59,913 point All-Star
    • mudassarkhan
    • Member since 02-28-2008, 5:28 AM
    • Mumbai, India
    • Posts 10,551
    • TrustedFriends-MVPs

    ramireddyindia:

    thanks mudassarkhan, I know javascript is case - sensitive.

    I didn't write it in editor. I just typed here and gave it.

     

    Yes I know nothing as such I just corrected it

    It happens when we type here with me too

    Smile

     

Page 1 of 1 (5 items)