async function fetchEntry(){ var name = document.getElementById("name") var crs = document.getElementById("3alpha") var nlc = document.getElementById("nlc") var tiploc = document.getElementById("tiploc") var stanox = document.getElementById("stanox") var values = { name: name.value, crs: crs.value, nlc: nlc.value, tiploc: tiploc.value, stanox: stanox.value } console.log(`Read values: ${JSON.stringify(values)}`) parseData(values) } async function parseData(values){ if (values.crs != ""){ getData("crs", values.crs) } else if (values.nlc != ""){ getData("nlc", values.nlc) } else if (values.tiploc != ""){ getData("tiploc", values.tiploc) } else if (values.stanox != ""){ getData("stanox", values.stanox) } else if (values.name != ""){ getData("name", values.name) } else { errorNoData() } } async function getData(type, value){ console.log(`Looking for: ${type} ${value}`) try { var url = `${window.location.origin}/api/v1/${type}/${value}`; var resp = await fetch(url); console.log(`Response: ${resp.json}`) return await resp.json() } catch (err) { errorFetch(err) } } async function errorNoData(){ console.log("No data entered") window.alert("You haven't entered any data") } async function errorFetch(err){ console.log("Error fetching data") console.log(err) }