0

I've been trying to declare a global variable for a couple of hours now, but it just won't work ! I've tried executing them without using the "var" tag in a function, checked W3schools tutorials, but it just won't work. I'm trying to declare them in the pythagore() function. (Sorry if some of my names in the code are in french, but it should'nt cause any problems)

<html>
<head>
<script type="text/javascript">

var title = document.getElementById("title");

var res = document.getElementById("resultat");

var option = document.getElementById("type").value;

var help = document.getElementById("button");

var inA = document.getElementById("valeurA");

var inB = document.getElementById("valeurB");

function pythagore() {
res.innerHTML = Math.sqrt(Math.pow(inA.value,2)+Math.pow(inB.value,2))
}

function helpPythagore() {
alert("CÔTÉ A & B : les deux plus petits du triangle rectangle\n\nRÉSULTAT : longueur de l'hypothénuse\n\nLes mesures des longueurs doivent être les mêmes")
}

function option() {
document.getElementById("title").innerHTML = document.getElementById("type").value;
}

</script>

<style type="text/css">
input {
width: 100%;
}

#button {
width: 100%;
}
</style>

</head>
<body onload="option()">

<hr>

<fieldset>
<p id="menu" align="center">MENU
<br>
<select onchange="option()" id="type">
  <option value="PYTHAGORE">PYTHAGORE</option>
  <option value="COSINUS">COSINUS</option>
  <option value="SINUS">SINUS</option>
  <option value="TANGENTE">TANGENTE</option>
  <option value="AIRE">AIRE</option>
</select>
</p>
</fieldset>

<hr>

<p align="center" id="title">CLIQUER AU-DESSUS POUR SÉLECTIONNER UNE OPTION</p>

<hr>

<fieldset name="Valeur A">
   <legend>Côté A</legend>
   <input id="valeurA" type="text" onchange="pythagore()">
</fieldset>

<fieldset name="Valeur B">
   <legend>Côté B</legend>
   <input id="valeurB" type="text" onchange="pythagore()">
</fieldset>

<fieldset name="Résultat">
   <legend>Résultat</legend>
   <p id="resultat" align="center">0<p>
   <hr>
   <button id="button" onclick="helpPythagore()">AIDE</button>
</fieldset>

</body>
</html>
ninivert
  • 45
  • 9

0 Answers0