Pemrograman Web B - Tugas 3 : Membuat Pencarian Kode Pos
Tugas Pemrograman Web Membuat Pencarian Kode Pos
Andhika Ditya Bagaskara D.
5025201096
Untuk penugasan ketiga, kami membuat website pencarian kode pos dengan menggunakan HTML dan JS. Input dapat berupa Provinsi, Kabupaten / Kota, dan Kecamatan. Output yang diharapkan adalah semua data (Kode Pos) yang sesuai dengan input-input yang dimasukkan.
Untuk tugas ini, saya mengambil data kode pos dari file .JSON, kemudian di-read dalam JavaScript. HTML akan menerima input yang kemudian akan dipassing ke script yang telah dibuat. Script yang telah memiliki input variable akan mencocokan dengan data yang telah diread dari file .JSON, kemudian mengoutputkannya.
Link website dan repository yang telah dibuat adalah sebagai berikut:
Berikut ini potongan source code nya:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<link rel="stylesheet" href="style.css" /> | |
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<title>POLAR BEAR</title> | |
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto"> | |
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script> | |
<script src="script.js"></script> | |
</head> | |
<body> | |
<div id="container"> | |
<div class="content"> | |
<h1>POLAR BEAR EXPRESS</h1> | |
<p>INPUT DATA TO SEARCH THE POSTAL CODE</p> | |
<div class="table"> | |
<div class="table-row"> | |
<label class="table-cell">Province:</label> | |
<input type="text" class="table-cell" id="province" placeholder="Enter a province"> | |
</div> | |
<div class="table-row"> | |
<label class="table-cell">City:</label> | |
<input type="text" class="table-cell" id="city" placeholder="Enter a city"> | |
</div> | |
<div class="table-row"> | |
<label class="table-cell">Sub District:</label> | |
<input type="text" class="table-cell" id="subdistrict" placeholder="Enter a sub district"> | |
</div> | |
</div> | |
<div class="searchButton"> | |
<input type="submit" id="sButton" class="button" value="Search" /> | |
</div> | |
</div> | |
<div id="result"></div> | |
</div> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
* { | |
margin: 0; | |
padding: 0; | |
box-sizing: border-box; | |
font-family: 'Roboto'; | |
} | |
body { | |
background-image: linear-gradient(rgba(0, 0, 0, 0.3), rgba(0, 0, 0, 0.3)), | |
url(images/SE.jpg); | |
height: 100vh; | |
background-position: center; | |
background-repeat: no-repeat; | |
background-size: cover; | |
background-attachment: fixed; | |
} | |
#container { | |
margin: 30px 60px; | |
} | |
.content { | |
background-image: linear-gradient(rgba(0, 0, 0, 0.3), rgba(0, 0, 0, 0.3)), url(images/SELogo.jpg); | |
background-repeat: no-repeat; | |
background-size: cover; | |
padding: 50px; | |
border-radius: 1em; | |
margin: 0 150px; | |
color: aliceblue; | |
} | |
.content label, input { | |
font-weight: bold; | |
font-size: 1.3rem; | |
} | |
.content h1, p { | |
text-align: center; | |
font-weight: bold; | |
font-size: 1.5rem; | |
margin-bottom: 30px; | |
} | |
.content h1 { | |
font-size: 5rem; | |
margin-top: -30px; | |
margin-bottom: 20px; | |
} | |
.table { | |
margin-bottom: 15px; | |
display: table; | |
margin: 0 auto; | |
} | |
.table-row { | |
display: table-row; | |
} | |
.table-row input { | |
padding: 5px 5px; | |
} | |
.table-cell { | |
display: table-cell; | |
margin: 7px; | |
padding-right: 18px; | |
} | |
.searchButton { | |
text-align: center; | |
margin-top: 20px; | |
} | |
.button { | |
padding: 8px 15px; | |
background-color: crimson; | |
border-radius: 8px; | |
border-style: none; | |
transition: 0.4s; | |
color: aliceblue; | |
} | |
.button:hover { | |
background-color: brown; | |
color: aliceblue; | |
cursor: pointer; | |
} | |
#result { | |
max-width: 1080px; | |
margin: 40px auto; | |
color: aliceblue; | |
} | |
#result p { | |
margin-top: 25px; | |
} | |
#card_container { | |
display: flex; | |
column-gap: 30px; | |
justify-content: center; | |
flex-wrap: wrap; | |
color: aliceblue; | |
} | |
.card { | |
width: 280px; | |
padding: 15px; | |
border-radius: 8px; | |
background-color: brown; | |
margin-bottom: 30px; | |
transition: 0.3s; | |
} | |
.card:hover { | |
box-shadow: 0px 0px 30px 5px yellow; | |
transform: scale(1.1); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(document).ready(function() | |
{ | |
$.ajaxSetup({ async: false, cache: false }); | |
function search() | |
{ | |
var prov = $.trim($('#province').val()).toUpperCase(); | |
var city = $.trim($('#city').val()).toUpperCase(); | |
var subdst = $.trim($('#subdistrict').val()).toUpperCase(); | |
var sCount = 0; | |
$('#result').remove(); | |
$('#container').append('<div id="result"></div>'); | |
var sDiv = $('#result'); | |
$(sDiv).append('<h2>SEARCH RESULT</h2>'); | |
$(sDiv).append('<p><span id="info"></span></p>'); | |
$(sDiv).append('<div id="card_container"></div>'); | |
var sCContainer = $('#card_container'); | |
$.getJSON("data.json", function(result) | |
{ | |
$.each(result, function(key, val) { | |
if(val.province.search(prov) !== -1 && | |
val.city.search(city) !== -1 && | |
val.sub_district.search(subdst) !== -1) | |
{ | |
var sCDiv = $('<div class="card"></div'); | |
$(sCContainer).append(sCDiv); | |
$(sCDiv).append('<p>Province:</b> ' + val.province + '</p>'); | |
$(sCDiv).append('<p>City:</b> ' + val.city + '</p>'); | |
$(sCDiv).append('<p>Sub District:</b> ' + val.sub_district + '</p>'); | |
$(sCDiv).append('<p>Urban:</b> ' + val.urban + '</p>'); | |
$(sCDiv).append('<p>Postal Code:</b> ' + val.postal_code + '</p>'); | |
sCount++; | |
} | |
}); | |
}); | |
if(sCount != 0) | |
{ | |
$('#info').html('Data found: ' + sCount + ' data(s)'); | |
} | |
else | |
{ | |
$('#info').html('DATA NOT FOUND.'); | |
} | |
} | |
$('#sButton').click(function() | |
{ | |
search(); | |
}); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[ | |
{ | |
"urban": "ABAH LUENG", | |
"sub_district": "BANDAR BARU", | |
"city": "PIDIE JAYA", | |
"province": "ACEH", | |
"postal_code": "24184" | |
}, | |
{ | |
"urban": "ABAIL", | |
"sub_district": "TEUPAH TENGAH", | |
"city": "SIMEULUE", | |
"province": "ACEH", | |
"postal_code": "23891" | |
}, | |
{ | |
"urban": "ABEUK BUDI", | |
"sub_district": "JULI", | |
"city": "BIREUEN", | |
"province": "ACEH", | |
"postal_code": "24251" | |
}, | |
{ | |
"urban": "ABEUK GEULANTEU", | |
"sub_district": "MADAT", | |
"city": "ACEH TIMUR", | |
"province": "ACEH", | |
"postal_code": "24458" | |
}, | |
{ | |
"urban": "ABEUK JALOH", | |
"sub_district": "JANGKA", | |
"city": "BIREUEN", | |
"province": "ACEH", | |
"postal_code": "24261" | |
}, | |
{ | |
"urban": "ABEUK LEUPON (LEUPEN)", | |
"sub_district": "LHOKSUKON", | |
"city": "ACEH UTARA", | |
"province": "ACEH", | |
"postal_code": "24382" | |
} | |
] |
Komentar
Posting Komentar