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 6 of 6
  1. #1
    New to the CF scene
    Join Date
    Dec 2008
    Posts
    9
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Percentage Calculator

    Hi Everyone
    I am thinking about using the Percentage Calculator
    http://www.javascriptkit.com/script/...rcentage.shtml

    Code:
    <SCRIPT language=JavaScript>
    <!--
    //Script by Tom Richardson Jr.
    //If you have any questions, e-mail me at gooftroop@geocities.com
    //or visit mt web site at http://home.rmci.net/gooftroop
    //For this script and more, visit http://javascriptkit.com
    
    
    function perc1() {
     a = document.form1.a.value/100;
     b = a*document.form1.b.value;
     document.form1.total1.value = b
     }
    function perc2() {
     a = document.form1.c.value;
     b = document.form1.d.value;
     c = a/b;
     d = c*100;
     document.form1.total2.value = d
     }
    //-->
    </SCRIPT>
    
    <FORM name=form1>
    <TABLE cellSpacing=1 cellPadding=1 border=1>
      <TBODY>
      <TR>
        <TD align=middle colSpan=3><B><FONT size=4>Percentage Calculator</FONT></B> 
          </TD>
      <TR>
        <TD>What is <INPUT size=5 name=a> % of <INPUT size=5 name=b>?</TD>
        <TD>Answer: <INPUT maxLength=40 size=5 name=total1></TD>
        <TD><INPUT onclick=perc1() type=button value=Calculate></TD>
      <TR>
        <TD><INPUT size=5 name=c> is what percent of <INPUT size=5 
    name=d>?</TD>
        <TD>Answer: <INPUT size=5 name=total2> %</TD>
        <TD><INPUT onclick=perc2() type=button value=Calculate></TD>
      <TR>
        <TD align=middle 
    colSpan=3><INPUT type=reset value=Reset></TD></TR></TBODY></TABLE></FORM>
    Is there any way to add a drop down value menu instead of typing in the numbers ?
    Been a bit of a head scratcher for me so far


    Donna

  • #2
    Regular Coder
    Join Date
    Jul 2010
    Posts
    271
    Thanks
    3
    Thanked 40 Times in 40 Posts
    You can always do that but do you only want whole numbers and up to what number in each field?

  • #3
    Regular Coder
    Join Date
    Jul 2010
    Posts
    271
    Thanks
    3
    Thanked 40 Times in 40 Posts
    This will show you how you can go about it.

    <FORM name=form1>
    <TABLE cellSpacing=1 cellPadding=1 border=1>
    <TBODY>
    <TR>
    <TD align=middle colSpan=3><B><FONT size=4>Percentage Calculator</FONT></B>
    </TD>
    <TR>
    <TD>What is
    <script language="javascript">
    document.write("<select name=a>");
    var i=1;
    for (i=1;i<=100;i++)
    {
    document.write("<option value="+i+">"+i+"</option>");
    }
    </script>
    </select>
    % of <INPUT size=5 name=b>?</TD>

  • #4
    New to the CF scene
    Join Date
    Dec 2008
    Posts
    9
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Sorry should have been more clear
    I am trying to figure out how to add a text drop down menu and the number which is associated to the text.
    Does that make sense

  • #5
    Regular Coder
    Join Date
    Jul 2010
    Posts
    271
    Thanks
    3
    Thanked 40 Times in 40 Posts
    You will have fun doing the arrays if this is what you want.

    <TD>What is
    <script language="javascript">
    var iNumber=["Zero","One","Two","Three","Four","Five","Six","Seven","Eight","Nine","Ten"];
    document.write("<select name=a>");
    var i=0;
    for (i=0;i<=10;i++)
    {
    document.write("<option value="+i+">"+iNumber[i]+"</option>");
    }
    </script>
    </select>
    % of <INPUT size=5 name=b>?</TD>

  • #6
    New to the CF scene
    Join Date
    Dec 2008
    Posts
    9
    Thanks
    1
    Thanked 0 Times in 0 Posts
    I am going to be a pain here...
    Not quite what I had in mind ( but very close ), but you do your your stuff jimhill
    I would like something like this added..

    <option value=2926>************text**********</option>

    So the idea is to replace both boxes with this drop down menu style to give a overall percentage.


  •  

    Posting Permissions

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