473,387 Members | 1,541 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,387 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 2603
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.