This is a search function where if you input either values (1001, 1002, 1003)
Json record will be posted as list
Currently the Json Data is stored under Variable "data".
I want to have the ability to reference an external JSON file in the same folder as variable
so I am assuming something along the lines of:
var data = loadJson('jsonfilename.json');
However I tried a ton of variations and none of them work for.
Ideally, I'd like a solution without Jquery
<!DOCTYPE html>
<html>
<head>
<title>Webslesson Tutorial | Search HTML Table Data by using JQuery</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" />
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>
<input id="searchBox" type="text" />
<button id="button">
Search
</button>
<div>
<ul>
</ul>
</div>
<script>
var data = [
{ "type": "Feature", "properties": {
"RANK_BY_CD": "26",
"CDUID": "1001"} },
{ "type": "Feature", "properties": {
"RANK_BY_CD": "212",
"CDUID": "1002"} },
{ "type": "Feature", "properties": {
"RANK_BY_CD": "248",
"CDUID": "1003"} }
];
$(document).ready(function(){
$("#button").click(function (any_function_variable_name) {
var searchId = String($('#searchBox').val());
data.forEach(function (any_function_variable_name) {
if(any_function_variable_name.properties.CDUID == searchId){
$("ul")
.append('<li> <strong>CDUID: </strong>' + any_function_variable_name.properties.CDUID)
.append('<li> <strong>RANK_BY_CD: </strong>' + any_function_variable_name.properties.RANK_BY_CD);
}
});
});
});
</script>
</body>
</html>
External JSON - data.json
{
"type": "FeatureCollection",
"features": [
{ "type": "Feature", "properties": {
"RANK_BY_CD": "26",
"CDUID": "1001"} },
{ "type": "Feature", "properties": {
"RANK_BY_CD": "212",
"CDUID": "1002"} },
{ "type": "Feature", "properties": {
"RANK_BY_CD": "248",
"CDUID": "1003"} }
]}