Skip to content

Instantly share code, notes, and snippets.

@naeluh
Last active August 29, 2015 14:11
Show Gist options
  • Save naeluh/614fcd5d1fc7e1969167 to your computer and use it in GitHub Desktop.
Save naeluh/614fcd5d1fc7e1969167 to your computer and use it in GitHub Desktop.
var match = false;
$("#general_info_two").on("click", function () {
$("#list").html("");
$("#list").fadeOut(1E3);
$("#nameCity").fadeOut(1E3);
$("#selectBox option[value='option1']").remove();
$("#psa").remove();
if ($("#zip").val().length < 5) {
$('#notFound').html('<div id="psa" style="color:#DD5900;">Please Enter a 5 digit zipcode.</div>').show();
}
else {
$.ajax({
url: "./myfile.json",
dataType: "jsonp",
jsonpCallback: "functionReference",
beforeSend: function () {
$("#notFound").slideUp('fast');
$("#searchProgress").fadeIn(1E3);
$("input").attr('disabled', 'true');
},
success: function (data) {
$("#searchProgress").fadeOut(1E3);
$("input").removeAttr('disabled', 'true');
$("#list").prepend('<option value="Please Select School.">Please Select School.</option>');
var match = false;
for (var i = data.length - 1; i >= 0; i--) {
var schools = data[i].School;
var streets = data[i].Street;
var zips = data[i].Zip;
//var idxSchl = schools.indexOf(",");
//schools = schools.substring(0, idxSchl != -1 ? idxSchl : schools.length);
schools = schools.replace(',', ' ');
var idx = zips.indexOf("-");
zips = zips.substring(0, idx != -1 ? idx : zips.length);
var zipMatch = zips.toLowerCase() === $("#zip").val().toLowerCase();
if (zipMatch) {
match = true;
if (schools.length > 0 && streets.length > 0) {
$("#list").fadeIn(1E3);
$("#list").append('<option value="' + schools + '">' + schools + ", " + streets + "</option>");
schoolArray.push({
"A": data[i].A,
"B": data[i].B,
"C": data[i].C,
"E": data[i].E,
"F": data[i].F,
"G": data[i].G,
"H": data[i].H,
"I": data[i].I,
"H": data[i].H
});
}
}
}
if (match) {
$("#nameCity").fadeIn(1E3);
$("#notFound").hide();
}
else {
$("#notFound").fadeIn(1E3);
$("#notFound").html('<div id="psa">No schools were found. Please Enter a new zip.</div>');
}
},
error: function () {
$("input").removeAttr('disabled', 'true');
}
});
}
return false;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment