Script que ne se lance plus

Fermé
Pistache - 14 juin 2016 à 14:20
 Utilisateur anonyme - 14 juin 2016 à 20:10
Bonjour,
Je vous explique mon problème, j'ai fait un petit script pour qu'il me calcule automatique le total de nombre d'heure par semaine.
lundi + mardi + mercredi + jeudi + vendredi = total
Mais il ne se lance pas depuis la présence d'autre script qui marche eux par contre.

function controleh() { 
var variable1 = document.controleChamps.hlundi.value;
var variable2 = document.controleChamps.hmardi.value;
var variable4 = document.controleChamps.hmercredi.value;
var variable5 = document.controleChamps.hjeudi.value;
var variable6 = document.controleChamps.hvendredi.value;
if(variable1 !== "" && variable2 !== "" && variable4 !== ""&& variable5 !== ""&& variable6 !== "") {
var variable3 = Number("variable1") + Number("variable2") + Number("variable4") + Number("variable5") + Number("variable6");
document.getElementById("total1").value = variable3.toFixed(2);
} else {
document.getElementById("total1").value = "0";
}
}


                <td class="tg-yw4l" id="nprojet"><input type="text" class="nprojet" name="nprojet"  size="5"></td>
<td class="tg-yw4l" id="nom_lieu_chantier"><input type="text" class="nom_lieu_chantier" name="nom_lieu_chantier" size="20"></td>
<td class="tg-yw4l" id="ddclundi"><input type="text" class="ddclundi" name="ddclundi" size="2"></td>
<td class="tg-yw4l" id="dcclundi"><input type="text" class="dcclundi" name="dcclundi" size="2"></td>
<td class="tg-yw4l" id="hlundi"><input type="text" class="hlundi" name="hlundi" size="2"></td>
<td class="tg-yw4l" id="hlundisoir"><input type="text" class="hlundisoir" name="hlundisoir" size="2"></td>
<td class="tg-yw4l" id="ddcmardi"><input type="text" class="ddcmardi" name="ddcmardi" size="2"></td>
<td class="tg-yw4l" id="dccmardi"><input type="text" class="dccmardi" name="dccmardi" size="2"></td>
<td class="tg-yw4l" id="hmardi"><input type="text" class="hmardi" name="hmardi" size="2"></td>
<td class="tg-yw4l" id="hmardisoir"><input type="text" class="hmardisoir" name="hmardisoir" size="2"></td>
<td class="tg-yw4l" id="ddcmercredi"><input type="text" class="ddcmercredi" name="ddcmercredi" size="2"></td>
<td class="tg-yw4l" id="dccmercredi"><input type="text" class="dccmercredisoir" name="dccmercredisoir" size="2"></td>
<td class="tg-yw4l" id="hmercredi"><input type="text" class="hmercredi" name="hmercredi" size="2"></td>
<td class="tg-yw4l" id="hmercredisoir"><input type="text" class="hmercredisoir" name="hmercredisoir" size="2"></td>
<td class="tg-yw4l" id="ddcjeudi"><input type="text" class="ddcjeudi" name="ddcjeudi" size="2"></td>
<td class="tg-yw4l" id="dccjeudi"><input type="text" class="dccjeudi" name="dccjeudi" size="2" ></td>
<td class="tg-yw4l" id="hjeudi"><input type="text" class="hjeudi" name="hjeudi" size="2"></td>
<td class="tg-yw4l" id="hjeudisoir"><input type="text" class="hjeudisoir" name="hjeudisoir" size="2"></td>
<td class="tg-yw4l" id="ddcvendredi"><input type="text" class="ddcvendredi" name="ddcvendredi" size="2"></td>
<td class="tg-yw4l" id="dccvendredi"><input type="text" class="dccvendredi" name="dccvendredi" size="2"></td>
<td class="tg-yw4l" id="hvendredi"><input type="text" class="hvendredi" name="hvendredi" size="2" onClick="controleh();"></td>
<td class="tg-yw4l" id="hvendredisoir"><input type="text" class="hvendredisoir" name="hvendredisoir" size="2"></td> <br/>
<td class="tg-yw4l" id="CE">
<?php
include("../connexion.php");
echo "<select id='CE' classe='CE' name='CE'>";
$listeca = $connexion->query("SELECT * FROM chef_equipe");
foreach ($listeca as $ca)
{
echo '<option value='.$ca["nom"].'>'.$ca["nom"].'</option>';
} echo"<br/> "; echo'</select>';
?>
</tr>
<tr id="table1"> <br/></tr>
<tr id="table2"> </tr>

</table>
</div>
Totals: <input type="text" id="total1" name="total1" value="" readonly> <br/> <!-- Appel de la fonction total--> </form>

1 réponse

Bonjour

Ça m'étonnerait beaucoup que ce script marche, qu'il y en ait un autre ou non
Number("variable1")
ne donnera jamais un nombre, car "variable1" avec des " autour, ce n'est pas une variable mais une chaîne de caractères. Tu aurais dû écrire
Number(variable1)
.
0