Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 12 of 12

Thread: to torrent Girl

  1. #1
    Senior Coder
    Join Date
    Mar 2005
    Location
    Portsmouth UK
    Posts
    4,535
    Thanks
    3
    Thanked 513 Times in 500 Posts

    to torrent Girl

    see http://www.codingforums.com/showthread.php?t=89719

    from PM

    Hi Vic

    You posted some code in response to a question from me re: calculating dynamic form fields.

    Your code requires the user to click on a button to total the fields.

    Can this be changed to calculate using onBlur?

    thnx

    tGirl



    Yes

    put an onblur event call to the function in the ip text boxes

    Thought you were misleaded to follow the other somewhat dubious 'solution'

    also see link below -and look for Form Compendium
    Last edited by vwphillips; 06-24-2006 at 09:51 PM.
    Vic

    God Loves You and will never love you less.

    http://www.vicsjavascripts.org/Home.htm

    If my post has been useful please donate to http://www.operationsmile.org.uk/

  • #2
    New Coder
    Join Date
    Jun 2006
    Location
    NYC
    Posts
    21
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Great

    thanks

    Checking out your site now
    tGirl

  • #3
    New Coder
    Join Date
    Jun 2006
    Location
    NYC
    Posts
    21
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Vic

    I added the onBlur and implemented your code into mine.

    I don't get an error but it is not totalling.

    I get a ZERO in the total field on the first onBlur


    Here is one of my form fields:

    <input name="<cfoutput>annualWrittenPremium#j#</cfoutput>" type="text" class="ip" onBlur="zxcCalculate('T1');" value="<cfoutput>#Evaluate("AnnualWrittenPremium" & j)#</cfoutput>" size="12" maxlength="12" />

    NOTICE THAT THE NAME OF THE FIELD IS DYNAMICALLY CREATED WITH A LOOP/INDEX


    Here is my total field (also dynamically created):

    <input type="Text" name="<cfoutput>annualWPremPersonalAutoTOTAL#i#</cfoutput>" class="st" onBlur="zxcCalculate('T1');" size="12" value="<cfoutput>#Evaluate("annualWPremPersonalAutoTOTAL" & i)#</cfoutput>" maxlength="12" />


    any suggestions?








    added
    tGirl

  • #4
    Senior Coder
    Join Date
    Mar 2005
    Location
    Portsmouth UK
    Posts
    4,535
    Thanks
    3
    Thanked 513 Times in 500 Posts
    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    
    <head>
      <title></title>
    </head>
    <script type="text/javascript">
    
    function zxcCalculate(zxcid){
     var zxctable=document.getElementById(zxcid);
     var zxcrows=zxctable.getElementsByTagName('TR');
     var zxcstary=[];
     var zxcgtotal=0;
     var zxcgtotalip=null;
     for (var zxc0=0;zxc0<zxcrows.length;zxc0++){
      var zxcstotal=0;
      var zxcstotalip=null;
      var zxcips=zxcrows[zxc0].getElementsByTagName('INPUT');
      for (var zxc1=0;zxc1<zxcips.length;zxc1++){
       if (zxcips[zxc1].className.match('ip')){
        if (zxcips[zxc1].value.length>0&&!isNaN(zxcips[zxc1].value)){
         zxcstotal+=zxcips[zxc1].value*1;
        }
       }
       if (zxcips[zxc1].className.match('st')){
        zxcstary[zxc0]=zxcips[zxc1];
       }
       if (zxcips[zxc1].className.match('gt')){
        zxcgtotalip=zxcips[zxc1];
       }
      }
      if (zxcstary[zxc0]){ zxcstary[zxc0].value=zxcstotal; zxcgtotal+=zxcstotal; }
     }
     if (zxcgtotalip){ zxcgtotalip.value=zxcgtotal; }
    }
    
    
    
    </script>
    <body >
    <table id="T1"border="1">
      <tr>
        <td width="100" ><input class="ip" type="text" size="4" onblur="zxcCalculate('T1');" ></td>
        <td width="100" ><input class="ip" type="text" size="4" onblur="zxcCalculate('T1');"  ></td>
        <td width="100" ><input class="ip" type="text" size="4" onblur="zxcCalculate('T1');"  ></td>
        <td width="100" ><input class="st" type="text" size="4" onblur="zxcCalculate('T1');"  ></td>
      </tr>
      <tr>
        <td width="100" ><input class="ip" type="text" size="4" onblur="zxcCalculate('T1');"  ></td>
        <td width="100" ><input class="ip" type="text" size="4" onblur="zxcCalculate('T1');"  ></td>
        <td width="100" ><input class="ip" type="text" size="4" onblur="zxcCalculate('T1');"  ></td>
        <td width="100" ><input class="st" type="text" size="4" onblur="zxcCalculate('T1');"  ></td>
      </tr>
      <tr>
        <td width="100" ></td>
        <td width="100" ></td>
        <td width="100" ><input class="gt" type="text" size="4"  ></td>
        <td width="100" ><input type="button" value="Calculate" onclick="zxcCalculate('T1');"  ></td>
      </tr>
    </table>
    </body>
    
    </html>
    Vic

    God Loves You and will never love you less.

    http://www.vicsjavascripts.org/Home.htm

    If my post has been useful please donate to http://www.operationsmile.org.uk/

  • #5
    New Coder
    Join Date
    Jun 2006
    Location
    NYC
    Posts
    21
    Thanks
    0
    Thanked 0 Times in 0 Posts
    that is what I have

    it still does not calulate.
    tGirl

  • #6
    Senior Coder
    Join Date
    Mar 2005
    Location
    Portsmouth UK
    Posts
    4,535
    Thanks
    3
    Thanked 513 Times in 500 Posts
    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    
    <head>
      <title></title>
    </head>
    <script type="text/javascript">
    
    function zxcCalculate(zxcid){
     var zxctable=document.getElementById(zxcid);
     var zxcrows=zxctable.getElementsByTagName('TR');
     var zxcstary=[];
     var zxcgtotal=0;
     var zxcgtotalip=null;
     for (var zxc0=0;zxc0<zxcrows.length;zxc0++){
      var zxcstotal=0;
      var zxcstotalip=null;
      var zxcips=zxcrows[zxc0].getElementsByTagName('INPUT');
      for (var zxc1=0;zxc1<zxcips.length;zxc1++){
       if (zxcips[zxc1].className.match('ip')){
        if (zxcips[zxc1].value.length>0&&!isNaN(zxcips[zxc1].value)){
         zxcstotal+=zxcips[zxc1].value*1;
        }
       }
       if (zxcips[zxc1].className.match('st')){
        zxcstary[zxc0]=zxcips[zxc1];
       }
       if (zxcips[zxc1].className.match('gt')){
        zxcgtotalip=zxcips[zxc1];
       }
      }
      if (zxcstary[zxc0]){ zxcstary[zxc0].value=zxcstotal; zxcgtotal+=zxcstotal; }
     }
     if (zxcgtotalip){ zxcgtotalip.value=zxcgtotal; }
    }
    
    
    
    </script>
    <body >
    <table id="T1"border="1">
      <tr>
        <td width="100" ><input class="ip" type="text" size="4" onmouseout="zxcCalculate('T1');" ></td>
        <td width="100" ><input class="ip" type="text" size="4" onmouseout="zxcCalculate('T1');"  ></td>
        <td width="100" ><input class="ip" type="text" size="4" onmouseout="zxcCalculate('T1');"  ></td>
        <td width="100" ><input class="st" type="text" size="4" onmouseout="zxcCalculate('T1');"  ></td>
      </tr>
      <tr>
        <td width="100" ><input class="ip" type="text" size="4" onmouseout="zxcCalculate('T1');"  ></td>
        <td width="100" ><input class="ip" type="text" size="4" onmouseout="zxcCalculate('T1');"  ></td>
        <td width="100" ><input class="ip" type="text" size="4" onmouseout="zxcCalculate('T1');"  ></td>
        <td width="100" ><input class="st" type="text" size="4" onmouseout="zxcCalculate('T1');"  ></td>
      </tr>
      <tr>
        <td width="100" ></td>
        <td width="100" ></td>
        <td width="100" ><input class="gt" type="text" size="4"  ></td>
        <td width="100" ><input type="button" value="Calculate" onclick="zxcCalculate('T1');"  ></td>
      </tr>
    </table>
    </body>
    
    </html>
    Vic

    God Loves You and will never love you less.

    http://www.vicsjavascripts.org/Home.htm

    If my post has been useful please donate to http://www.operationsmile.org.uk/

  • #7
    New Coder
    Join Date
    Jun 2006
    Location
    NYC
    Posts
    21
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Can someone please help me with this code that should calulate dynamic form fields?

    I have an A.M.


    I'm Desparate
    tGirl

  • #8
    Senior Coder
    Join Date
    Mar 2005
    Location
    Portsmouth UK
    Posts
    4,535
    Thanks
    3
    Thanked 513 Times in 500 Posts
    each row is calulated individualy

    your row have two inputs class="ip" which are calculated
    but no input class='st'(sub total) to retain the result

    all inputs class="st" are summed to produce the grand total.

    without a class="st" in the row the sum of its inputs will not be included

    you need an input class="st" in each row

    make this type 'text' untill you are satisfied then make type 'hidden'

    study and use the example I posted
    Vic

    God Loves You and will never love you less.

    http://www.vicsjavascripts.org/Home.htm

    If my post has been useful please donate to http://www.operationsmile.org.uk/

  • #9
    New Coder
    Join Date
    Jun 2006
    Location
    NYC
    Posts
    21
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Ok thanks!!
    tGirl

  • #10
    New Coder
    Join Date
    Jun 2006
    Location
    NYC
    Posts
    21
    Thanks
    0
    Thanked 0 Times in 0 Posts
    So do I apply the class="st" to the actual <TR>?
    tGirl

  • #11
    teh Moderatorinator
    Join Date
    Sep 2004
    Location
    USA
    Posts
    2,472
    Thanks
    4
    Thanked 40 Times in 40 Posts
    Use the example posted and go from their...
    Code:
    <td width="100" ><input class="st" type="text" size="4" onmouseout="zxcCalculate('T1');"  ></td>

  • #12
    New Coder
    Join Date
    Jun 2006
    Location
    NYC
    Posts
    21
    Thanks
    0
    Thanked 0 Times in 0 Posts

    It works



    BUT

    The code is on a loop and on the second loop it doesn't work.


    Any suggestions?
    tGirl


  •  

    Posting Permissions

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