Auto Populating Form

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #16
    Originally posted by dpi
    Thanks, that all makes sense, but it still wont do anything.
    http://www.rotarytrici ties.com/test.html
    I checked the link. You have extra stuff that does not make sense at all. What are <csaction> and <scscriptdict > tags? That's not HTML. Also, for your calculate button, you are calling CSAction and CSClickReturn functions which do not seem to be defined. At least, that's what Firefox complains about when I tested it.

    One final thing, in your calculate() function, there are two spaces between the dot and "value". Remove that too.

    Comment

    • dpi
      New Member
      • Jan 2007
      • 11

      #17
      I havew no clue what that stuff is, it doesnt show up in my code offline. The spaces came in when I pasted the code from here, I thought I removed them.

      Luckily, I did figure out how to do it.

      Code:
      function dm(amount) 
      {
        string = "" + amount;
        dec = string.length - string.indexOf('.');
        if (string.indexOf('.') == -1)
        return string + '.00';
        if (dec == 1)
        return string + '00';
        if (dec == 2)
        return string + '0';
        if (dec > 3)
        return string.substring(0,string.length-dec+3);
        return string;
      }
      
      
      
      function calculate()
      {
      
        QtyA = 0;  QtyB = 0;  QtyC = 0; QtyD = 0; QtyE = 0; QtyF = 0; QtyG = 0;
        TotA = 0;  TotB = 0;  TotC = 0; TotD = 0; TotE = 0; TotF = 0; TotG = 0;
      
        PrcA = 160; PrcB = 95; PrcC = 75; PrcD = 75; PrcE = 65; PrcF = 50; PrcG = 50;
      
       
       
        if (document.ofrm.qtyA.value > "")
           { QtyA = document.ofrm.qtyA.value };
        document.ofrm.qtyA.value = eval(QtyA);  
       
        if (document.ofrm.qtyB.value > "")
           { QtyB = document.ofrm.qtyB.value };
        document.ofrm.qtyB.value = eval(QtyB);  
       
        if (document.ofrm.qtyC.value > "")
           { QtyC = document.ofrm.qtyC.value };
        document.ofrm.qtyC.value = eval(QtyC);
        
          if (document.ofrm.qtyD.value > "")
           { QtyD = document.ofrm.qtyD.value };
        document.ofrm.qtyD.value = eval(QtyD);
        
        if (document.ofrm.qtyE.value > "")
           { QtyE = document.ofrm.qtyE.value };
        document.ofrm.qtyE.value = eval(QtyE);
        
        if (document.ofrm.qtyF.value > "")
           { QtyF = document.ofrm.qtyF.value };
        document.ofrm.qtyF.value = eval(QtyF);
        
        if (document.ofrm.qtyG.value > "")
           { QtyG = document.ofrm.qtyG.value };
        document.ofrm.qtyG.value = eval(QtyG);
       
       
        TotA = QtyA * PrcA;
        document.ofrm.totalA.value = dm(eval(TotA));
       
        TotB = QtyB * PrcB;
        document.ofrm.totalB.value = dm(eval(TotB));
       
        TotC = QtyC * PrcC;
        document.ofrm.totalC.value = dm(eval(TotC));
        
         TotD = QtyD * PrcD;
        document.ofrm.totalD.value = dm(eval(TotD));
        
           TotE = QtyE * PrcE;
        document.ofrm.totalE.value = dm(eval(TotE));
        
           TotF = QtyF * PrcF;
        document.ofrm.totalF.value = dm(eval(TotF));
        
           TotG = QtyG * PrcG;
        document.ofrm.totalG.value = dm(eval(TotG));
       
       
        Totamt = 
           eval(TotA) +
           eval(TotB) +
           eval(TotC) +
           eval(TotD) +
           eval(TotE) +
           eval(TotF) +
           eval(TotG) ;
          
        document.ofrm.GrandTotal.value = dm(eval(Totamt));
        
      } 
      
      
      function validNum(theForm)
      {
        var checkOK = "0123456789.,";
        var checkStr = theForm.qtyA.value;
        var allValid = true;
        var validGroups = true;
        var decPoints = 0;
        var allNum = "";
        for (i = 0;  i < checkStr.length;  i++)
        {
          ch = checkStr.charAt(i);
          for (j = 0;  j < checkOK.length;  j++)
            if (ch == checkOK.charAt(j))
              break;
          if (j == checkOK.length)
          {
            allValid = false;
            break;
          }
          if (ch == ".")
          {
            allNum += ".";
            decPoints++;
          }
          else if (ch == "," && decPoints != 0)
          {
            validGroups = false;
            break;
          }
          else if (ch != ",")
            allNum += ch;
        }
        if (!allValid)
        {
          alert("Please enter only digit characters in the \"Class A quantity\" field.");
          theForm.qtyA.focus();
          return (false);
        }
      
        if (decPoints > 1 || !validGroups)
        {
          alert("Please enter a valid number in the \"Class A quantity\" field.");
          theForm.qtyA.focus();
          return (false);
        }
      
        var checkOK = "0123456789.,";
        var checkStr = theForm.qtyB.value;
        var allValid = true;
        var validGroups = true;
        var decPoints = 0;
        var allNum = "";
        for (i = 0;  i < checkStr.length;  i++)
        {
          ch = checkStr.charAt(i);
          for (j = 0;  j < checkOK.length;  j++)
            if (ch == checkOK.charAt(j))
              break;
          if (j == checkOK.length)
          {
            allValid = false;
            break;
          }
          if (ch == ".")
          {
            allNum += ".";
            decPoints++;
          }
          else if (ch == "," && decPoints != 0)
          {
            validGroups = false;
            break;
          }
          else if (ch != ",")
            allNum += ch;
        }
        if (!allValid)
        {
          alert("Please enter only digit characters in the \"Class B quantity\" field.");
          theForm.qtyB.focus();
          return (false);
        }
      
        if (decPoints > 1 || !validGroups)
        {
          alert("Please enter a valid number in the \"Class B quantity\" field.");
          theForm.qtyA.focus();
          return (false);
        }
      
        var checkOK = "0123456789.,";
        var checkStr = theForm.qtyC.value;
        var allValid = true;
        var validGroups = true;
        var decPoints = 0;
        var allNum = "";
        for (i = 0;  i < checkStr.length;  i++)
        {
          ch = checkStr.charAt(i);
          for (j = 0;  j < checkOK.length;  j++)
            if (ch == checkOK.charAt(j))
              break;
          if (j == checkOK.length)
          {
            allValid = false;
            break;
          }
          if (ch == ".")
          {
            allNum += ".";
            decPoints++;
          }
          else if (ch == "," && decPoints != 0)
          {
            validGroups = false;
            break;
          }
          else if (ch != ",")
            allNum += ch;
        }
        if (!allValid)
        {
          alert("Please enter only digit characters in the \"Class C quantity\" field.");
          theForm.qtyC.focus();
          return (false);
        }
      
        if (decPoints > 1 || !validGroups)
        {
          alert("Please enter a valid number in the \"Class C quantity\" field.");
          theForm.qtyC.focus();
          return (false);
        }
      
      
        calculate();
        return (true);
      }

      Comment

      • acoder
        Recognized Expert MVP
        • Nov 2006
        • 16032

        #18
        Glad you got it working.

        Comment

        • dpi
          New Member
          • Jan 2007
          • 11

          #19
          Originally posted by acoder
          Glad you got it working.
          Thanks for all your help.

          Cory Wright
          Graphicworx

          Comment

          Working...