"Booking slots"
Bootstrap 3.0.0 Snippet by zeeshanmazhar

1
2
3
4
5
6
7
8
9
10
11
12
13
<link href="//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css" rel="stylesheet" id="bootstrap-css">
<script src="//netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js"></script>
<script src="//code.jquery.com/jquery-1.11.1.min.js"></script>
<!------ Include the above in your HEAD tag ---------->
<div class="container">
<div class="row">
<h2>Booking Slots:</h2>
<table class="table-bordered">
<tbody class="reservationTable"></tbody>
</table>
</div>
</div>
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
td{
height: 30px;
min-width: 120px;
margin: 5px;
border-radius: 2px;
}
.booked{
background-color: red;
}
.selected{
background-color: white;
}
.vacant{
background-color: green;
}
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
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
var numArray = [];
$(document).ready(function(){
createReservationTable(5,5);
});
$(document).on('click', '.vacant', function() {
if ($(this).hasClass("vacant")) {
idValue = $(this).attr('id');
$(this).removeClass("vacant");
$(this).addClass("selected");
numArray.push(idValue);
}
});
$(document).on('click', '.selected', function() {
idValue = $(this).attr('id');
remove(numArray,idValue);
$(this).removeClass("selected");
$(this).addClass("vacant");
});
function createReservationTable(rows, cols){
for (var i = 1; i <= rows; i++) {
$('.reservationTable').append('<tr id="'+i+'" class="tr-'+i+'">');
for (var j = 1; j <= cols; j++) {
$('.tr-'+i+'').append('<td id="'+i+'.'+j+'" class="vacant"></td>');
}
$('.reservationTable').append('</tr>');
}
}
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Related: See More


Questions / Comments: