469,648 Members | 1,582 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,648 developers. It's quick & easy.

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

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
Nov 18 '05 #1
4 2476
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:ed**************@tk2msftngp13.phx.gbl...
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

Nov 18 '05 #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:ed**************@tk2msftngp13.phx.gbl...
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

Nov 18 '05 #3
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]" <No************@comcast.netNoSpamM> wrote
in message news:%2****************@TK2MSFTNGP12.phx.gbl...
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:ed**************@tk2msftngp13.phx.gbl...
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


Nov 18 '05 #4
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:%2****************@TK2MSFTNGP12.phx.gbl...
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]" <No************@comcast.netNoSpamM> wrote in message news:%2****************@TK2MSFTNGP12.phx.gbl...
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:ed**************@tk2msftngp13.phx.gbl...
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



Nov 18 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

By using this site, you agree to our Privacy Policy and Terms of Use.