Show sourcecode
The following files exists in this folder. Click to view.
webbserv1-bas0-start/exercises/
aside.php
form-quiz-3/
formular7.php
funktioner.php
grunder.php
index.php
string4.php
string4_form.php
formular7.php
73 lines UTF-8 Unix (LF)
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
<!doctype html>
<html lang="sv">
<head>
<meta charset="utf-8">
<title>Formulär 7</title>
<style type="text/css">
ul {
list-style: none;
margin: 0;
padding: 0;
}
label {
display: inline-block;
width: 100px;
}
button {
margin: 1em 0;
}
h4 {
margin: 1em 0 0.5em 0;
}
</style>
</head>
<body>
<h3>Formulär 7</h3>
<form action="" method="post">
<ul>
<li><label>Tal 1:</label> <input name="nr1" type="text" value="0" /></li>
<li><label>Tal 2:</label> <input name="nr2" type="text" value="0" /></li>
<li><label>Tal 3:</label> <input name="nr3" type="text" value="0" /></li>
<li><button type="submit">Beräkna</button></li>
</ul>
</form>
<?php
if(isset($_POST['nr1']) && $_POST['nr1'] != "") {
$nr1 = $_POST['nr1'];
} else {
$nr1 = 0;
}
if(isset($_POST['nr2']) && $_POST['nr2'] != "") {
$nr2 = $_POST['nr2'];
} else {
$nr2 = 0;
}
if(isset($_POST['nr3']) && $_POST['nr3'] != "") {
$nr3 = $_POST['nr3'];
} else {
$nr3 = 0;
}
$medel = medel($nr1, $nr2, $nr3);
echo "<p>De tre talen: $nr1, $nr2, $nr3<br/>";
echo "Medelvärdet: $medel</p>";
// -----------------------------------------------------------------------
// Calculate mean-value from 3 arguments
// -----------------------------------------------------------------------
function medel($nr1, $nr2, $nr3) {
$sum = $nr1 + $nr2 + $nr3;
return $sum / 3;
}
?>
</body>
</html>