JSFiddle - React, Tailwind, and code Playground
by yura747
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title> TEST NEW </title>
<link rel="stylesheet" href="css/style.css">
</head>
<body>
<form id="zip">
<input type="text" name="zip" id="input" onkeyup='checkParams()' placeholder="Please, enter your zip code" maxlength='5'>
<button type="submit" class="btn" onclick='submitFunk()' disabled>Click to add your city</button>
</form>
<p>Add your zip code. 00210 : 99950 for the US</p>
<a href="http://www.structnet.com/instructions/zip_min_max_by_state.html"> Here is the list with US zip codes</a>
<ul id="places">
<li>Santa Maria, CA</li>
<li>Los Angeles, CA</li>
<li>Schenectady, NY</li>
</ul>
<a href="sssssssssssssssss" class="jsfiddle">Here you can find my HTML, CSS and JS codes</a>
<script src="js/jquery-3.3.1.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
<script src="js/main.js"></script>
</body>
</html>
CSS
@media all and (max-width: 300px) {
form {
max-width: 90%;
width: 90%;
}
}
#zip {
display: table;
border: rgb(160, 160, 160) 2px solid;
width: 340px;
}
#zip > #input, #zip > .btn{
display: table-cell;
white-space: nowrap;
border: 1px solid #ccc;
box-sizing: border-box;
padding: 10px;
}
#zip > #input {
width: 57%;
}
#zip > .btn {
border-left: none;
width: 43%;
cursor: pointer;
color: rgba(255,255,255,.9);
text-shadow: #2e7ebd 0 1px 2px;
border-color: #60a3d8 #2970a9 #2970a9 #60a3d8;
box-shadow: inset rgba(255,255,255,.5) 1px 1px;
background-color: #60a3d8;
}
#zip >.btn:disabled {
color: gray;
border-color: #2980b9;
background-color: #2980b9;
cursor: default;
}
#zip > .btn:hover {
color: rgb(255,255,255);
border-color: #2970a9;
background-image: linear-gradient(#5796c8, #6aa2ce);
box-shadow: none;
}
#zip > #input.error{
background-color: rgba(245, 222, 179);
}
li {
width: 300px;
list-style: none;
list-style-image: url(https://png.icons8.com/small/2x/map-pin.png);
margin-bottom: 1px;
border-radius: 20px;
text-align: center;
color: rgba(255,255,255,.9);
text-shadow: #2e7ebd 0 1px 2px;
text-decoration: none;
text-align: center;
line-height: 1.1;
white-space: pre-line;
border: 1px solid;
border-color: #60a3d8 #2970a9 #2970a9 #60a3d8;
border-radius: 6px;
outline: none;
background: #60a3d8 linear-gradient(#89bbe2, #60a3d8 50%, #378bce);
box-shadow: inset rgba(255,255,255,.5) 1px 1px;
}
li:hover {
text-decoration: line-through;
padding-bottom: 1px;
color: rgb(255,255,255);
background-image: linear-gradient(#9dc7e7, #74afdd 50%, #378bce);
}
p {
margin-left: 30px;
height: 10px;
}
a:not(.jsfiddle) {
margin-left: 70px;
}
.jsfiddle {
margin-left: 20px;
}
JavaScript
// submit is blocked
$('form').submit(function( e ){
$('input[type=submit]', $(this)).prop( 'disabled', true );
e.preventDefault();
});
// clean input after submit
$('.btn').on('click', function() {
$(this).closest('form').find('input[type=text], textarea').val('');
});
// Begin code with " " is not alowed
$("input#input").on({
keydown: function(e) {
if (e.which === 32)
return false;
},
change: function() {
this.value = this.value.replace(/\s/g, "");
}
});
// only numbers allowed
$("input#input").keyup(function(e){
this.value = this.value.replace(/[^0-9\.]/g, '');
});
// Before you add text button is disabled
function checkParams() {
var codeLg = $('#input').val();
if(codeLg.length != 0 && codeLg.length > 4) {
$('.btn').removeAttr('disabled');
$('#input').removeClass('error')
} else {
$('.btn').attr('disabled', 'disabled');
$('#input').addClass('error')
}
}
// ZIPPOPOTAM
// $(function() {
// // OnKeyDown Function
// $("#input").keyup(function() {
// // Make HTTP Request
// $.ajax({
// url: "http://api.zippopotam.us/us/" + $('#input').val(),
// cache: false,
// dataType: "json",
// type: "GET",
// success: function(result, success) {
// // US Zip Code Records Officially Map to only 1 Primary Location
// places = result['places'][0];
// // ------------------------------------------
// },
// error: function(result, success) {
// $('.btn').attr('disabled', 'disabled');
// $('#input').addClass('error')
// }
// });
// });
// });
$("#input").keyup(function() {
inputCode = $(this).val();
});
function submitFunk() {
if (inputCode.length > 4) {
var requestURL = "http://api.zippopotam.us/us/" + inputCode;
var request = new XMLHttpRequest();
request.open('GET', requestURL);
request.responseType = 'json';
request.send();
...