+ Reply to Thread
Results 1 to 3 of 3

Thread: adding numbers

  1. #1
    Barn Loyal todd2006 is an unknown quantity at this point todd2006's Avatar
    Join Date
    Mar 2008
    Posts
    889
    Rep Power
    4

    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) 
    
    }
    
    }
    

  2. #2
    Barn Legend Rebelle will become famous soon enough Rebelle's Avatar
    Join Date
    Mar 2008
    Posts
    1,522
    Rep Power
    5

    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.

  3. #3
    The Barnfather jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead's Avatar
    Join Date
    Mar 2008
    Location
    Reston, VA
    Posts
    4,547
    Blog Entries
    9
    Real Name
    Jason
    Rep Power
    22

    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
    If you agree, give me rep.
    If you like it here...throw us a few bones to help support us.


+ Reply to Thread

Similar Threads

  1. Alpha Page Numbers
    By AOG123 in forum Microsoft Access
    Replies: 4
    Last Post: March 19th, 2008, 12:24 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

SEO by vBSEO