forked from zwilsondev/application-test
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
65 lines (60 loc) · 2.41 KB
/
index.php
File metadata and controls
65 lines (60 loc) · 2.41 KB
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
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script>
$(function () {
var people = <?php
echo json_encode(array(
array('id' => 1, 'first_name' => 'John', 'last_name' => 'Smith', 'email' => 'john.smith@hotmail.com'),
array('id' => 2, 'first_name' => 'Paul', 'last_name' => 'Allen', 'email' => 'paul.allen@microsoft.com'),
array('id' => 3, 'first_name' => 'James', 'last_name' => 'Johnston', 'email' => 'james.johnston@gmail.com'),
array('id' => 4, 'first_name' => 'Steve', 'last_name' => 'Buscemi', 'email' => 'steve.buscemi@yahoo.com'),
array('id' => 5, 'first_name' => 'Doug', 'last_name' => 'Simons', 'email' => 'doug.simons@hotmail.com')
));
?>;
//set table tag
var table = $('<table/>');
//append title and header
table.append('<caption><h1>Test application</h1></caption><tr><th>ID</th><th>First Name</th><th>Last Name</th><th>E-mail</th><th>Action</th></tr>');
//append people array into the table
$.each(people, function (i, value) {
var row = $('<tr/>');
$.each(value, function (k, v) {
row.append($('<td/>').text(v));
});
row.append($('<button class="showRow">Click Me!</button>'));
table.append(row);
});
//add table to the page
$('.content').append(table);
$('.showRow').click(function () {
var name = $(this).closest('tr').find('td:eq(1)').text();
var email = $(this).closest('tr').find('td:eq(3)').text();
alert('Name: ' + name+'\nEmail: ' + email);
});
});
</script>
<style>
table {
font-family: arial, sans-serif;
border-collapse: collapse;
width: 100%;
}
td, th {
border: 1px solid #dddddd;
text-align: left;
padding: 8px;
}
tr:nth-child(even) {
background-color: #dddddd;
}
</style>
</head>
<body>
<div class="content">
</div>
</body>
</html>