I think your first mistake is your not using a JS framework, so the event attaching is probably not happening like @klugerama stated. I've provided a JSFiddle based on what I think you're trying to do here, http://jsfiddle.net/nickyt/wKPdv/
Here's the JS from that fiddle:
// using jQuery as you really should be using a JS framework, but if not you could attach events using pure JS, but then you need to manage attaching events for all browsers.
var patientZipContext = $("#patientZip");
var patientCityContext = $("#patientCity");
var patientStateContext = $("#patientState");
var showHiddenContext = $("#showHidden");
console.log(patientZipContext)
console.log(patientCityContext)
console.log(patientStateContext)
function populateCityState(zipCode) {
// Whatever your code does. Returning dummy code for now.
return ["someCity", "someState"];
}
showHiddenContext.on("click", function() {
$("input[type='hidden']").each(function() {
this.setAttribute("type", "text");
})
});
patientZipContext.on("change", function() {
var cityState;
console.log("onchange fired");
cityState = populateCityState(this.value);
// code to handle empty or incomplete array goes here
patientCityContext.val(cityState[0]);
patientStateContext.val(cityState[1]);
});