PDA

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

Avalikia
03-05-2005, 09:16 PM
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!

Mr J
03-06-2005, 12:45 AM
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>