PDA

View Full Version : option & script help


dean84
05-04-2009, 02:34 PM
Hi guys, im pretty new to javascript and im trying to create a page for an online game that me and a few of my friends play

The idea of the page is to help us with our village outlay, so that when we click a building level it tells us the points of the level and the villagers it uses at that level

I have worked out the Points side of it, but am getting stuck on how to do the villagers part

Here is the basic page (not finished as im just testing out the coding first)
www.stateofwar.co.uk/villagecalc.html (http://www.stateofwar.co.uk/villagecalc.html)

Here is the code that i have so far

<HTML>

<HEAD>

<TITLE>Village Calculator</TITLE>

<script language="JavaScript">

function HEADQUARTERSPOINTS()
{
var phq;
phq=document.getElementById("HEADQUARTERS").value;
result=parseFloat(phq);
document.sumForm.PHEADQUARTERS.value=result;

var pba;
pba=document.getElementById("BARRACKS").value;
result=parseFloat(pba);
document.sumForm.PBARRACKS.value=result;
}

function TOTALPOINTS()
{
var num1,num2;
num1=document.getElementById("PHEADQUARTERS").value;
num2=document.getElementById("PBARRACKS").value;
result=parseFloat(num1)+parseFloat(num2);
document.sumForm.Answer.value=result;
}
</script>

</HEAD>

<BODY BGCOLOR="white">

<H1>Village Calculator</H1>

<form name="sumForm">
<table width="300" border="1" bordercolor="#000000">
<tr><td>Building</td><td>Level</td><td>Points</td><td>Villagers</td></tr>
<tr><td align="right">Village Headquarters:</td><td>
<select name="HEADQUARTERS" id="HEADQUARTERS" onBlur="HEADQUARTERSPOINTS()">
<option value="0">0</option>
<option value="10">1</option>
<option value="12">2</option>
<option value="14">3</option>
<option value="17">4</option>
<option value="21">5</option>
<option value="25">6</option>
<option value="30">7</option>
<option value="36">8</option>
<option value="43">9</option>
<option value="52">10</option>
<option value="62">11</option>
<option value="74">12</option>
<option value="89">13</option>
<option value="107">14</option>
<option value="128">15</option>
<option value="154">16</option>
<option value="185">17</option>
<option value="222">18</option>
<option value="266">19</option>
<option value="319">20</option>
<option value="383">21</option>
<option value="460">22</option>
<option value="552">23</option>
<option value="662">24</option>
<option value="795">25</option>
<option value="954">26</option>
<option value="1145">27</option>
<option value="1374">28</option>
<option value="1648">29</option>
<option value="1978">30</option>
</select></td>
<td><input type="text" name="PHEADQUARTERS" id="PHEADQUARTERS" size="4" readonly="true" value="0"></td>
<td><input type="text" name="VHEADQUARTERS" id="VHEADQUARTERS" size="4" readonly="true" value="0"></td></tr>
<tr><td align="right">Barracks:</td><td><select name="BARRACKS" id="BARRACKS" onBlur="HEADQUARTERSPOINTS()">
<option value="0">0</option>
<option value="16">1</option>
<option value="19">2</option>
<option value="23">3</option>
<option value="28">4</option>
<option value="33">5</option>
<option value="40">6</option>
<option value="48">7</option>
<option value="57">8</option>
<option value="69">9</option>
<option value="83">10</option>
<option value="99">11</option>
<option value="119">12</option>
<option value="143">13</option>
<option value="171">14</option>
<option value="205">15</option>
<option value="247">16</option>
<option value="296">17</option>
<option value="355">18</option>
<option value="426">19</option>
<option value="511">20</option>
<option value="613">21</option>
<option value="736">22</option>
<option value="883">23</option>
<option value="1060">24</option>
<option value="1272">25</option>
</select></td>
<td><input type="text" name="PBARRACKS" id="PBARRACKS" size="4" readonly="true" value="0"></td>
<td><input type="text" name="VBARRACKS" id="VBARRACKS" size="4" readonly="true" value="0"></td></tr>
<tr><td align="right">Stable:</td><td><select name="STABLE" id="STABLE">
<option value="0">0</option>
<option value="20">1</option>
<option value="24">2</option>
<option value="29">3</option>
<option value="35">4</option>
<option value="41">5</option>
<option value="50">6</option>
<option value="60">7</option>
<option value="72">8</option>
<option value="86">9</option>
<option value="103">10</option>
<option value="124">11</option>
<option value="149">12</option>
<option value="178">13</option>
<option value="214">14</option>
<option value="257">15</option>
<option value="308">16</option>
<option value="370">17</option>
<option value="444">18</option>
<option value="532">19</option>
<option value="639">20</option>
</select></td></tr>
</table>
<p><input type="button" value="Press to calculate" name="B1" onClick="TOTALPOINTS()"></p>

<p>Answer:

</p>

<p><input type="text" name="Answer" size="20"></p>

</form>

<!--end of form-->

</BODY>

</HTML>

dean84
05-04-2009, 02:36 PM
(not acurate, but just for an example)

Headquarters

1 - 10 points - 5 villagers
2 - 12 points - 6 villagers
3 - 14 points - 7 villagers
4 - 16 points - 9 villagers