473,326 Members | 2,134 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

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 2600
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Harry | last post by:
Hello, I have an ASP.Net web page populated with WebControls, such as textboxes and checkboxes. On this page I also have a JavaScript that disables these textboxes under certain events (such as...
4
by: Davisro | last post by:
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....
27
by: Chris | last post by:
Hi, I have a form for uploading documents and inserting the data into a mysql db. I would like to validate the form. I have tried a couple of Javascript form validation functions, but it...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.