11-02-2008, 08:24 PM
Oui vas-y, je poste la version corrigé
Code PHP :
<?php
<table style="text-align : center; ">
<tr>
<td>Agilité :</td>
<td>Force : </td>
<td>Intelligence</td>
<td>Culture</td>
<td>Total : </td>
</tr>
<tr>
<td><input type="text" name="agil" size="10" style="text-align : center;" id="agil" value="0" onkeyup="utiliser('utili', this);" /></td>
<td><input type="text" name="force" size="10" style="text-align : center;" id="force" value="0" onkeyup="utiliser('utili', this);" /></td>
<td><input type="text" name="intel" size="10" style="text-align : center;" id="intel" value="0" onkeyup="utiliser('utili', this);" /></td>
<td><input type="text" name="culture" size="10" style="text-align : center;" id="culture" value="0" onkeyup="utiliser('utili', this);" /></td>
<td><input type="text" disabled="disabled" name="total" size="10" style="text-align : center;" id="utili" value="0/40" /></td>
</tr></table>
<table style="text-align : center; width : 100%;"><tr><td>
<input type="text" size="45" disabled="disabled" value="Il vous reste 40 points a utiliser" id="reste">
</td></tr></Table>
<script type="text/javascript">
function $(elem){return document.getElementById(elem);}
function utiliser(id, item) {
var total = 40;
var use = 0;
var before = 0;
var stats = new Array("agil", "force", "intel", "culture");
for(var i in stats)
{
use += $(stats[i]).value*1;
if(stats[i] != item.id)
{
before += $(stats[i]).value*1;
}
}
if(use > total)
{
item.value = total - before; use = total;
}
$(id).value = use+'/40';
var reste = total - use;
if( reste > 0 ) { $('reste').value = 'Il vous reste '+reste+' points a utiliser'; }
else
{ $('reste').value = 'Vous n\'avez plus de points a utiliser'; }
}
</script>