Created
May 7, 2025 17:00
-
-
Save alvilawr/8c203d6f2ffa2a3fb2c44a8a6881856a to your computer and use it in GitHub Desktop.
Simple function to allow users to enter zip code and return a designated coach
This file contains hidden or 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"> | |
<title>Coach Zip Code Lookup</title> | |
<script src="https://cdn.jsdelivr.net/npm/xlsx/dist/xlsx.full.min.js"></script> | |
<style> | |
body { | |
font-family: Segoe, "Segoe UI", "DejaVu Sans", "Trebuchet MS", Verdana, "sans-serif"; | |
padding: 2rem; | |
background: #512667; | |
display: flex; | |
flex-direction: column; | |
align-items: center; | |
text-align: center; | |
} | |
h3 { | |
color: #fff; | |
} | |
input, button { | |
padding: 0.5rem; | |
margin-right: 1rem; | |
font-size: 1rem; | |
} | |
#result { | |
margin-top: 1rem; | |
font-weight: bold; | |
color: #fff; | |
} | |
</style> | |
</head> | |
<body> | |
<h3>Enter your zip code<br>to find your coach</h3> | |
<input type="text" id="zipInput" placeholder="Enter zip code"> | |
<button onclick="lookupCoach()">Search</button> | |
<div id="result"></div> | |
<script> | |
let zipMap = {}; | |
// URL to hosted Zips_Regions.xlsx file | |
const fileUrl = 'Zips_Regions.xlsx'; | |
fetch(fileUrl) | |
.then(response => response.arrayBuffer()) | |
.then(arrayBuffer => { | |
const data = new Uint8Array(arrayBuffer); | |
const workbook = XLSX.read(data, { type: 'array' }); | |
const sheet = workbook.Sheets[workbook.SheetNames[0]]; | |
const json = XLSX.utils.sheet_to_json(sheet); | |
// Build zip to coach/region map | |
json.forEach(row => { | |
const zip = parseInt(row['Zip Code']); | |
const coach = row['Assigned EL Coach']; | |
const region = row['Region']; | |
if (!isNaN(zip) && coach && region) { | |
zipMap[zip] = { coach, region }; | |
} | |
}); | |
console.log('Zips_Regions.xlsx loaded dynamically.'); | |
}) | |
.catch(error => { | |
console.error('Error loading spreadsheet:', error); | |
}); | |
function lookupCoach() { | |
const zip = parseInt(document.getElementById('zipInput').value); | |
if (isNaN(zip)) { | |
document.getElementById('result').textContent = 'Please enter a valid zip code.'; | |
return; | |
} | |
const match = zipMap[zip]; | |
if (match) { | |
document.getElementById('result').innerHTML = `You’ve been matched with ${match.coach} in ${match.region}!<br>We’ll reach out to you with next steps.`; | |
} else { | |
document.getElementById('result').textContent = 'No coach found for this zip code.'; | |
} | |
} | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment