startit/MVC/intro.html

66 lines
1.7 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Intro</title>
</head>
<body>
<div id="app">
</div>
<script>
// Model
let firstName = "...her kommer et navn";
let place = "..her kommer et sted";
let food = "...her kommer en matrett";
// View
updateView();
function updateView() {
let html = `
<div class="group">
<div>Hei jeg heter</div>
<div id="namediv"> ${firstName}<br></div>
</div>
<div class="group">
<div>Jeg bor i</div>
<div id="placediv"> ${place}<br></div>
</div>
<div class="group">
<div>Min favorittmat er</div>
<div id="fooddiv"> ${food}<br></div>
</div>
<button onclick="setFields()">Klikk her for å sett inn verdier</button>
Navn: <input type="text" onchange="setName(this.value)">
Sted: <input type="text" onchange="setPlace(this.value)">
Mat: <input type="text" onchange="setFood(this.value)">
`;
document.getElementById('app').innerHTML = html;
}
// Controller
function setName(nameInput) {
firstName = nameInput;
updateView();
}
function setPlace(placeInput) {
place = placeInput;
updateView();
}
function setFood(foodInput) {
food = foodInput;
updateView();
}
</script>
<style>
.group {
display: flex;
padding: 3px;
}
</style>
</body>
</html>