-
Notifications
You must be signed in to change notification settings - Fork 2
/
test.html
55 lines (44 loc) · 1.64 KB
/
test.html
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
<!DOCTYPE html>
<html>
<head>
<title>Test 1</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/handlebars.js/4.0.5/handlebars.js"></script>
<script id="result-template" type="text/x-handlebars-template">
<h2>Your Bio</h2>
<p>
Your name is {{firstname}} {{lastname}} and you are {{age}} years old.
</p>
</script>
<link rel="stylesheet" href="style.css" type="text/css" />
</head>
<body>
<h2>Render Simple Bio</h2>
<input type="text" id="firstname" placeholder="First Name">
<br/>
<input type="text" id="lastname" placeholder="Last Name">
<br/>
<input type="number" id="age" placeholder="Age">
<br/>
<button id="demoButton">Demo</button>
<script>
document.addEventListener("DOMContentLoaded", function () {
//Get the contents from the script block
var source = document.querySelector("#result-template").innerHTML;
//Compile that baby into a template
template = Handlebars.compile(source);
document.querySelector("#demoButton").addEventListener("click", function () {
var fname = document.querySelector("#firstname").value;
var lname = document.querySelector("#lastname").value;
var age = document.querySelector("#age").value;
var html = template({
firstname: fname,
lastname: lname,
age: age
});
document.querySelector("#resultDiv").innerHTML = html;
});
});
</script>
<div id="resultDiv"></div>
</body>
</html>