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 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Mar 2005
    Location
    Utah
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    I need to set up a number conversion thing and don't know how.

    I'm working on a role-playing game and need a way to let the members easily convert ages from human to the equivalent of the other races in the game and vice versa. I'm thinking of having something along the lines of a text box to put the number to be converted in, some way to select whether you're changing the number to or from human years, a list of races for you to choose from, a button for when you're done, and a text box that shows the result. I know how to set up the various form elements, but I don't know how to write the code that takes the selected options, does the math, and displays in the the result.

    If someone can either explain how to do it or give me a link to a place that teaches you that sort of thing, I'd really appreciate it. It's high time I learned how to do this sort of thing!

  • #2
    Senior Coder
    Join Date
    Aug 2002
    Location
    UK
    Posts
    2,789
    Thanks
    2
    Thanked 14 Times in 14 Posts
    Here's the basics, but it would help to have some age ratios to work with



    <script language="javascript">
    <!--

    function convertme(){

    input1=document["f1"]["t1"].value

    for(i=0;i<document["f1"]["r1"].length;i++){
    if(document["f1"]["r1"][i].checked){
    race=document["f1"]["r1"][i].value
    }
    }

    if(document["f1"]["r2"][0].checked){
    convert=input1/race


    document["f1"]["converted"].value=convert
    }
    else{

    convert=input1*race
    document["f1"]["converted"].value=convert
    }

    }

    //-->
    </script>

    <form name="f1">
    Age <input type="text" name="t1" value="1" size="3" maxlength="3"><BR>
    Race 1<input type="radio" name="r1" value="5" checked> 5<BR>
    Race 2<input type="radio" name="r1" value="7"> 7<BR>
    Race 3<input type="radio" name="r1" value="9"> 9<BR>
    Race 4<input type="radio" name="r1" value="15"> 15<BR>
    Race 5<input type="radio" name="r1" value="20"> 20<BR>
    Convertion <input type="text" name="converted"><BR><BR>

    To Human <input type="radio" name="r2">
    From Human <input type="radio" name="r2" checked>
    <input type="button" value="convert" onclick="convertme()">
    </form>


    Last edited by Mr J; 03-06-2005 at 12:11 AM.
    The silent one.

    The most dangerous thing in the world is an idea.
    The most dangerous person in the world is the one with an idea.

  • #3
    New to the CF scene
    Join Date
    Mar 2005
    Location
    Utah
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Oh, that's great just the way it is! I can see in the coding how to edit the ratios and labels for the radio buttons myself, which is good because I want to be able to add more races later when I need them (and I will).


  •  

    Posting Permissions

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