Just thought I'd post the source for an Arena Calculator I made a while back in Javascript, hopefully someone might be able to learn from it or even use it!
It uses CSS for the layout and style and does the calculations realtime :-)
Heres a live demo: http://decelo.ulmb.com
index.html
HTML Code:
<html>
<head>
<script src="arena.js"></script>
<link rel="stylesheet" type="text/css" href="style.css" />
</head>
<body>
<div class="content">
<h>Arena Claculator</h>
<hr />
<br />
<div id="points2">2v2 Points......0</div>
<div id="points3">3v3 Points......0</div>
<div id="points5">5v5 Points......0</div>
<br />
<FORM NAME = formRating>
Rating: <input class="input" type="text" method="post" name="Ratings" value="0" id="fname" onkeypress="updateAll(this.id)" onkeyup="updateAll(this.id)" onClick="javascript:select();">
</FORM>
</div>
</body>
</html>
arena.js
Code:
function calcPoints(rating,size)
{
if (isNaN(rating))
return 0;
var points = 0;
if (rating < 1500)
{
points = (0.22 * rating + 14);
}
else
{
points = (1511.26 / (1 + 1639.28 * Math.pow(2.71828,(-0.00412 * rating))));
}
if (points < 0)
return 0;
else if (size == 2)
return Math.floor(points * 0.76);
else if (size == 3)
return Math.floor(points * 0.88);
else if (size == 5)
return Math.floor(points)
}
function update(x,size)
{
var y = document.getElementById(x).value;
var rating;
rating = parseInt(y);
if (y=="")
{
document.getElementById('points'+size).innerHTML = size + "v" + size + " Points......0";
}
else
{
document.getElementById('points'+size).innerHTML = size + "v" + size + " Points......" + calcPoints(rating,size);
}
}
function updateAll(rating)
{
update(rating,2);
update(rating,3);
update(rating,5);
}
style.css
Code:
body
{
background: #ebebeb;
text-align:center;
}
.container
{
position: relative;
}
.content
{
border: 1px solid #9e9e9e;
padding:5px;
margin:auto;
padding-top:15px;
padding-bottom:15px;
font-family:verdana,tahoma;
font-weight:normal;
color:#9e9e9e;
font-size:12px;
text-align:center;
width:250px;
position: relative;
top:200px;
}
.content h
{
font-weight:bold;
font-family:verdana,tahoma;
color:#9e9e9e;
font-size:18px;
}
.content hr
{
height: 1px;
border: 0px;
background-color: #9E9E9E;
color: #9E9E9E;
}
.content div
{
font-size:15px;
text-align: center;
}
.content form
{
font-size:15px;
text-align: center;
}
.input
{
color: #9e9e9e;
background: #ebebeb;
border: 1px solid #9e9e9e;
width:60px;
text-align: center;
}