Javascript into ASP.Net Simple example wanted.. Sum Textboxes client side

Discussion in 'ASP .Net' started by Davisro, Apr 9, 2004.

  1. Davisro

    Davisro Guest

    I would like to have a total box show the totol of four textboxes when
    anyone of them change.

    I know I could do this via postback, but would like to do this on client
    side utilizing javascript.

    I am familiar with asp.net but not in how to migrate javascript into the
    html.

    Thanks,

    Rog
     
    Davisro, Apr 9, 2004
    #1
    1. Advertising

  2. Here is one idea (will need tweaking):

    <input type="text" id="sumBox" name="sumBox" onFocus="SumBoxes();" />


    <script language="JavaScript">
    function SumBoxes()
    {
    var val1 = form1.addBox1.Value;
    var val2 = form2.addBox1.Value;
    var val3 = form3.addBox1.Value;
    var val4 = form4.addBox1.Value;

    //May need test for "" on each box here, turn to 0, like
    if(val1 == '')
    {
    val1 = 0;
    }

    form1.sumBox.Value = val1 + val2 + val3 + val4;
    }
    </script>

    --
    Gregory A. Beamer
    MVP; MCP: +I, SE, SD, DBA

    ***************************************************************
    Think outside the box!
    ***************************************************************
    "Davisro" <NA> wrote in message
    news:...
    > I would like to have a total box show the totol of four textboxes when
    > anyone of them change.
    >
    > I know I could do this via postback, but would like to do this on client
    > side utilizing javascript.
    >
    > I am familiar with asp.net but not in how to migrate javascript into the
    > html.
    >
    > Thanks,
    >
    > Rog
    >
    >
     
    Cowboy \(Gregory A. Beamer\) [MVP], Apr 9, 2004
    #2
    1. Advertising

  3. Davisro

    Curt_C [MVP] Guest

    if you want it with clientside javascript I suggest you look at a clientside
    javascript newsgroup.
    you'll probably have to catch the keydown/keyup in the boxes.

    --
    Curt Christianson
    Owner/Lead Developer, DF-Software
    www.Darkfalz.com


    "Davisro" <NA> wrote in message
    news:...
    > I would like to have a total box show the totol of four textboxes when
    > anyone of them change.
    >
    > I know I could do this via postback, but would like to do this on client
    > side utilizing javascript.
    >
    > I am familiar with asp.net but not in how to migrate javascript into the
    > html.
    >
    > Thanks,
    >
    > Rog
    >
    >
     
    Curt_C [MVP], Apr 9, 2004
    #3
  4. Davisro

    Davisro Guest

    I would like to use WebForm Textboxes as I have a lot of .Net code that
    relates to them. Is this possible in mostly the same way you stated above?

    Thanks,

    Rog
    "Cowboy (Gregory A. Beamer) [MVP]" <> wrote
    in message news:%...
    > Here is one idea (will need tweaking):
    >
    > <input type="text" id="sumBox" name="sumBox" onFocus="SumBoxes();" />
    >
    >
    > <script language="JavaScript">
    > function SumBoxes()
    > {
    > var val1 = form1.addBox1.Value;
    > var val2 = form2.addBox1.Value;
    > var val3 = form3.addBox1.Value;
    > var val4 = form4.addBox1.Value;
    >
    > //May need test for "" on each box here, turn to 0, like
    > if(val1 == '')
    > {
    > val1 = 0;
    > }
    >
    > form1.sumBox.Value = val1 + val2 + val3 + val4;
    > }
    > </script>
    >
    > --
    > Gregory A. Beamer
    > MVP; MCP: +I, SE, SD, DBA
    >
    > ***************************************************************
    > Think outside the box!
    > ***************************************************************
    > "Davisro" <NA> wrote in message
    > news:...
    > > I would like to have a total box show the totol of four textboxes when
    > > anyone of them change.
    > >
    > > I know I could do this via postback, but would like to do this on client
    > > side utilizing javascript.
    > >
    > > I am familiar with asp.net but not in how to migrate javascript into the
    > > html.
    > >
    > > Thanks,
    > >
    > > Rog
    > >
    > >

    >
    >
     
    Davisro, Apr 9, 2004
    #4
  5. For insert JavaScript on client page you can use RegisterClientScriptBlock
    or RegisterStartupScript method.
    string s = "<script language=\"JavaScript\">\n" +
    "function SumBoxes()\n" +
    "{\n" +
    ............
    "}\n" +
    "</script>\n";

    RegisterClientScriptBlock("SUM", s);

    for attach this function to your textbox you can use this code :
    txtBox1.Attributes["OnChange"] = "SumBoxes();";

    Brun

    "Davisro" <NA> wrote in message
    news:%...
    > I would like to use WebForm Textboxes as I have a lot of .Net code that
    > relates to them. Is this possible in mostly the same way you stated

    above?
    >
    > Thanks,
    >
    > Rog
    > "Cowboy (Gregory A. Beamer) [MVP]" <>

    wrote
    > in message news:%...
    > > Here is one idea (will need tweaking):
    > >
    > > <input type="text" id="sumBox" name="sumBox" onFocus="SumBoxes();" />
    > >
    > >
    > > <script language="JavaScript">
    > > function SumBoxes()
    > > {
    > > var val1 = form1.addBox1.Value;
    > > var val2 = form2.addBox1.Value;
    > > var val3 = form3.addBox1.Value;
    > > var val4 = form4.addBox1.Value;
    > >
    > > //May need test for "" on each box here, turn to 0, like
    > > if(val1 == '')
    > > {
    > > val1 = 0;
    > > }
    > >
    > > form1.sumBox.Value = val1 + val2 + val3 + val4;
    > > }
    > > </script>
    > >
    > > --
    > > Gregory A. Beamer
    > > MVP; MCP: +I, SE, SD, DBA
    > >
    > > ***************************************************************
    > > Think outside the box!
    > > ***************************************************************
    > > "Davisro" <NA> wrote in message
    > > news:...
    > > > I would like to have a total box show the totol of four textboxes when
    > > > anyone of them change.
    > > >
    > > > I know I could do this via postback, but would like to do this on

    client
    > > > side utilizing javascript.
    > > >
    > > > I am familiar with asp.net but not in how to migrate javascript into

    the
    > > > html.
    > > >
    > > > Thanks,
    > > >
    > > > Rog
    > > >
    > > >

    > >
    > >

    >
    >
     
    Bruno Sirianni, Apr 10, 2004
    #5
    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. Davisro
    Replies:
    2
    Views:
    6,649
    Davisro
    Apr 20, 2004
  2. Harvey
    Replies:
    0
    Views:
    790
    Harvey
    Jul 16, 2004
  3. Harvey
    Replies:
    1
    Views:
    896
    Daniel
    Jul 16, 2004
  4. =?Utf-8?B?cnQ=?=
    Replies:
    2
    Views:
    977
    =?Utf-8?B?cnQ=?=
    Jun 30, 2005
  5. Boss302
    Replies:
    0
    Views:
    1,102
    Boss302
    Nov 21, 2006
Loading...

Share This Page