Skip to content

Instantly share code, notes, and snippets.

@hemache
Created April 30, 2014 21:17
Show Gist options
  • Save hemache/1b15ffd4bf99d130fdb2 to your computer and use it in GitHub Desktop.
Save hemache/1b15ffd4bf99d130fdb2 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html>
<head>
<title>Souhail Moslim</title>
<script>
window.ajouter = function ()
{
var fieldset = document.getElementById("moyennes"),
input = document.createElement("input");
input.type = "number";
input.name = "moyenne[]";
input.placeholder="Moyenne";
input.min = 0;
input.max = 20;
input.maxlength = 2;
fieldset.insertBefore(input, fieldset.firstChild);
input.focus();
};
</script>
<style>
#moyennes > input
{
display: block;
width: 120px;
}
</style>
</head>
<body>
<?php if(isset($_POST["calc"])): ?>
<?php
$somme = 0;
foreach($_POST["moyenne"] as $moyenne) $somme += $moyenne;
$moyenneGeneral = $somme / count($_POST["moyenne"]);
?>
<h1>Moyenne General: <?php print $moyenneGeneral ?></h1>
<?php else: ?>
<h1>Saisir</h1>
<form method="post">
<button type="button" onclick="ajouter()">
Ajouter un autre input-box!
</button>
<fieldset id="moyennes">
<legend>
Moyennes
</legend>
<input type="number" name="moyenne[]" placeholder="Moyenne" min="0" max="20" maxlength="2" />
</fieldset>
<input type="submit" name="calc" value="calculer" />
</form>
<?php endif ?>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment