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

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

1. ## 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!

• 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>

• 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
•