DeveloperBarn Forums

Go Back   DeveloperBarn Forums > Programming & Scripting > JavaScript Programming

Discuss "adding numbers" in the JavaScript Programming forum.

JavaScript Programming - Javascript is a cross-browser client-side scripting language. Discuss Javascript and AJAX related scripts here.


Reply « Previous Thread | Next Thread »  
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old July 3rd, 2008, 12:11 PM
Contributing Member

 
Join Date: Mar 2008
Posts: 188
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 1
todd2006 is an unknown quantity at this point
Default adding numbers

Hi,

i have 3 textboxes I am trying to add the numbers that will entered in those textboxes

Here is my code

It gives me an error saying
document.frm1.txt1.value is null or not an object

any idea

Code:
<input type="text" name="txt1" id="txt1" onblur="callcal();" value="0">
<input type="text" name="txt2" id="txt2" onblur="callcal();" value="0">
<input type="text" name="txt3" id="txt3" onblur="callcal();" value="0">


function callcal()

{

var gettxt1=document.frm1.txt1.value;
if(gettxt1=="")
{
	gettxt1="0";
}

var gettxt2=document.frm1.txt2.value;
if(gettxt2=="")
{
	gettxt2="0";
}

var gettxt3=document.frm1.txt3.value;
if(gettxt3=="")
{
	gettxt3="0";
}

if(gettxt1=="" && gettxt2 =="" && gettxt3=="")
{
finaltotal="0"
}
else
{
finaltotal=parseInt(gettxt1) + parseInt(gettxt2) + parseInt(gettxt3) 

}

}
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old July 3rd, 2008, 01:36 PM
Rebelle's Avatar
Contributing Member

 
Join Date: Mar 2008
Posts: 165
Thanks: 32
Thanked 1 Time in 1 Post
Rep Power: 1
Rebelle is on a distinguished road
Default

todd2008,

here is a link to an example of what you are trying to do....it has more than what you need, just leave out the average stuff and i think it will help you.

Javascript Examples - JAVASCRIPTS: Total and Average Input Numbers

you can click run code on that page and see how it works.
Reply With Quote
  #3 (permalink)  
Old July 3rd, 2008, 01:38 PM
jmurrayhead's Avatar
Your Lord & Master

 
Join Date: Mar 2008
Location: Reston, VA, USA
Posts: 543
Thanks: 14
Thanked 41 Times in 40 Posts
Blog Entries: 2
Rep Power: 1
jmurrayhead will become famous soon enough

Awards Showcase
Microsoft SQL Server Microsoft Windows Microsoft .Net Classic ASP 
Total Awards: 4

Default

Try this:

Code:
<input type="text" name="txt1" id="txt1" onblur="callcal();" value="0">
<input type="text" name="txt2" id="txt2" onblur="callcal();" value="0">
<input type="text" name="txt3" id="txt3" onblur="callcal();" value="0">
<script language="Javascript" type="text/javascript">
function callcal()
{
var gettxt1=document.getElementById('txt1');
if(gettxt1.value =="")
{
 gettxt1="0";
}
var gettxt2=document.getElementById('txt2');
if(gettxt2.value =="")
{
 gettxt2="0";
}
var gettxt3=document.getElementById('txt3');
if(gettxt3.value =="")
{
 gettxt3="0";
}
if(gettxt1=="" && gettxt2 =="" && gettxt3=="")
{
finaltotal="0"
}
else
{
finaltotal=parseInt(gettxt1.value) + parseInt(gettxt2.value) + parseInt(gettxt3.value) 
}
}
</script>
__________________
jmurrayhead
Did I help you out? Make me popular by clicking the icon!

If you found a post helpful, please click the button in the lower right-hand corner of the post.

Powered by ASP.Net
Reply With Quote
Reply

  DeveloperBarn Forums > Programming & Scripting > JavaScript Programming

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Alpha Page Numbers AOG123 Microsoft Access 4 March 19th, 2008 11:24 AM


Sponsored Links

ASP.NET Resource Index
a directory of ASP.NET tutorials, applications, scripts, assemblies and articles for the novice to professional developer.

Free Web Directory
Including Chats and Forums Resources, Offer automatic, instant and free directory submissions.
URLZ Web Directory
URLZ Web Directory

Free Web Directory - Add Your Link
The Little Web Directory
Free Web Directory
Pegasus free web directory is a free directory organised by categories.

Web Directory & SEO Services
dirroot web directory


All times are GMT -4. The time now is 01:03 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.2.0
Copyright © 2008 DeveloperBarn.com

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46