1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
| <html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>calculatrice</title>
<script type="text/javascript" language="javascript">
<!--
var a=0;
var b=0;
function init() {
a=Number (document.calculette.nombre1.value);
b=Number (document.calculette.nombre2.value);
alert(a%1);
// Nombre1 est-il un nombre?
if ((!a) && (a!=0)) {
alert("Nombre1 n'est pas un chiffre : "+a);
return false;
}
// Nombre2 est-il un nombre?
if (!b) && (b!=0)) {
alert("Nombre2 n'est pas un chiffre : "+b);
return false;
}
return true;
}
function addition() {
if (init()) {
document.calculette.resultat.value=a+b;
}
}
function soustraction() {
if init()) {
document.calculette.resultat.value=a-b;
}
}
function multiplication() {
init()) {
document.calculette.resultat.value=a*b;
}
}
function division() {
if init()) {
if (b!=0) {
document.calculette.resultat.value=a/b;
else alert
}
}
//-->
</script>
</head>
<body>
<form name="calculette" method="post" action="">
<label for="decimales">Décimales</label>
<select name="decimales" id="decimales">
<option value="0">1</option>
<option value="1">2</option>
<option value="2">3</option>
</select>
<br>
<label for="nombre1">Nombre 1</label>
<input type="text" name="nombre1" id="nombre1" value="">
<br>
<label for="nombre2">Nombre 2</label>
<input type="text" name="nombre2" id="nombre2" value="">
<br>
<input type="button" name="plus" value="+" onclick="addition();">
<input type="button" name="moins" value="-" onclick="soustraction();">
<input type="button" name="fois" value="*" onclick="multiplication();">
<input type="button" name="divise" value="/" onclick="division();">
<br>
<label for="resultat">Résultat</label>
<input type="text" name="resultat" id="resultat" value="">
</body>
</html> |
Partager