I think I'm missing something here. This Jquery Mobile web application is for viewing information about parking lots in a specific city.
Basically, the application is loading, parsing and then appending JSON data onto a page. Then there is a textbox input and a button. Based on the textbox input, it only displays the data of parking spots which have the same number of spots specified in the textbox input. Basically viewing parking lot information based on a number of parking spots specified by the user. I have it somewhat working but the method that appends the data does not work on button click. Only when I refresh the page on my local browser does it load the values corresponding to the textbox. I do not want this and would like the list to update when I click the button.
Bit of the JSON parkingLots.JSON
{
"lotList":[
{
"id":1,
"lotName":"Jarvis St \/ Carleton St",
"availableSpots":8,
"totalSpots":15
}
]
}
main.js
var lotData;
$(document).ready(function()
{
$.getJSON({
url: "parkingLots.json",
mimeType: "application/json",
success: parseParkingLotsJSON
});
});
function parseParkingLotsJSON(data)
{
lotData = data.lotList;
for (var i=0; i < lotData.length; i++)
{
$("#size").append(appendLot(lotData[i], i));
};
}
function appendLot(lotData)
{
var lotName = lotData.lotName;
var lotId = lotData.id;
var lotAmount = lotData.availableSpots;
var key = $("#sizeId").val();
var size = $("<div " + lotId + "' data-role='table'>");
if ( lotAmount == key ) {
size.append("<h1>" + lotName + "</h1>");
size.append("<p> Lot ID: " + lotId + "</p>");
size.append("<p> Spots: " + lotAmount + "</p>");
}
return size;
}
index.html
<!DOCTYPE html>
<html lang="en">
<head>
<title>Parking Lot Web</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.css">
<link rel="stylesheet" href="main.css" />
<script src="http://code.jquery.com/jquery-2.2.4.min.js"></script>
<script src="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script>
<script src="https://maps.googleapis.com/maps/api/js?v=3.31"></script>
<script src="main.js"></script>
</head>
<h1>Parking Lot App</h1>
<body class="ui-page-theme-a">
<div data-role="page" id="home">
<h1 class="center">Parking App</h1>
<ul>
<a data-role="button" href='#page1'>Group Size</a>
</ul>
</div>
<div id="page1" data-role="page" data-filter="true" class="center">
<!--Where it's displayed on page-->
<h1 class="center" data-role="content">Search by Lot Size</h1>
<input type = "text" id = "sizeId"/>
<input type = "button" id = "sizeBtn" value = "search" onclick="appendLot(lotData)"/>
<div id="size" data-role="table" class="center"></div>
</div>
</div>
</body>
</html>
If you have any suggestions or have a way I would be able to get the data to load on button click instead of having to refresh, I would appreciate the help.