<script>
function Calc()
{
var priceitem = Number(document.getElementById('priceitem').value)
alert (priceitem)
var priceenchant = Number(document.getElementById('priceenchant').value)
alert (priceenchant)
var basicchance = Number(document.getElementById('basicchance').value)
alert (basicchance)
var safetyenchant = Number(document.getElementById('safetyenchant').value)
alert (safetyenchant)
var levelenchant = Number(document.getElementById('levelenchant').value)
alert (levelenchant)
var sum=0
var sumpriceitem = 0
if (levelenchant >= 0) and (levelenchant=<20)
{
if (basicchance >=1) and (basicchance=<100)
{
if (levelenchant > safetyenchant)
{
for (i=1; levelenchat-safetyenchant; i++)
{
sum = sum + (1 - (basicchance / 100) ^ i) * priceitem
}
}
sumpriceitem = priceitem + priceenchant * levelenchant + sum
document.getElementById('summary').value = sumpriceitem
}
else
{
alert=("Chance of successful enchant incorrect. Please, re-enter chance of enchant from 0 to 100")
}
}
else
{
alert=("Level of enchant incorrect. Please, re-enter level of enchant from 0 to 20")
}
}
</script>
Код:
|
<textarea id="priceitem" rows="1" value="100"></textarea>
<p>
<textarea id="priceenchant" rows="1" value="5"></textarea>
<p>
<textarea id="basicchance" rows="1" value="70"></textarea>
<p>
<textarea id="safetyenchant" rows="1" value="3"></textarea>
<p>
<textarea id="levelenchant" rows="1" value="4"></textarea>
<hr>
<textarea id="summary" rows="1" readonly="1"></textarea>
<p>
<button onclick="Calc()">Calc</button> |
И, почему-то, не вгоняет значения по умолчанию в текстовые поля.