I hope I don’t put you off helping others … I’ve located the backtick (new one on me) and input correctly but astill nothing changes. just the same as the screengrab from earlier…. code
any other ideas gratefully accepted
============
Javascript
============
function processJSONVenue({venueFilename, venueCtrlId, venueInfoId, dropDownLabel}) {
/**
* This function creates an HTML link from a value.
* It can be used to generate website, email or tel link
*/
const buildLink = (value, link = value) => {
return
<a href="${link}">${value}</a>
;
};
/**
* The following object comprises properties, each housing
* a function that produces HTML code responsible for formatting
* the branch item associated with the property's name.
*/
const fieldFormat = {
"name": v => 'Name: ' + v,
"email": v => buildLink(v, 'mailto:' + v),
"website": v => buildLink(v),
};
let fieldList = [];
function loadVenue() {
fetch(venueFilename)
.then(response => {
if (!response.ok) {
throw new Error('Unable to load the venue file');
}
return response.json();
})
.then(data => {
fieldList = data[0] ? Object.keys(data[0]) : [];
initVenue(data);
})
.catch(error => {
alert(error);
});
}
function initVenue(venues) {
const venueCtrl = document.getElementById(venueCtrlId);
const venueInfoEl = document.getElementById(venueInfoId);
/* Populating the drop-down field */
venueCtrl.innerHTML = <option value="0">${dropDownLabel}</option>
;
venues.forEach((venue, i) => {
const name = venue.name;
const venueItemObj = document.createElement('option');
venueItemObj.setAttribute('value', i + 1);
venueItemObj.appendChild(new Text(name));
venueCtrl.appendChild(venueItemObj);
});
/* Set event listener on drop-down when selection changes */
venueCtrl.addEventListener('change', () => {
const selectedId = venueCtrl.value - 1;
venueInfoEl.textContent = '';
if (selectedId < 0) {
return;
}
const venue = venues[selectedId];
fieldList.forEach(fieldName => {
if (venue[fieldName]) {
const fieldValue = venue[fieldName];
/* formats the field if a formatting function exists */
const fieldContent = fieldFormat[fieldName] ?
fieldFormat[fieldName](fieldValue) :
fieldValue;
const el = document.createElement('div');
el.className = "venue__" + fieldName;
el.innerHTML = fieldContent;
venueInfoEl.appendChild(el);
}
});
});
}
document.addEventListener('DOMContentLoaded', () => {
loadVenue();
});
}
/* ****************************************** */
/* update the following parameters as needed */
/* ****************************************** */
processJSONVenue(
{
venueFilename: '/wp-content/uploads/national-venues.json', // JSON file name
venueCtrlId: 'nationalVenue-ctrl', // ID of the drop-down
venueInfoId: 'nationalVenue-info', // ID of the DIV placeholder to display the branch info
dropDownLabel: 'Select a National Branch'
}
);
processJSONVenue(
{
venueFilename: '/wp-content/uploads/regional-venues.json', // JSON file name
venueCtrlId: 'regionalVenue-ctrl', // ID of the drop-down
venueInfoId: 'regionalVenue-info', // ID of the DIV placeholder to display the branch info
dropDownLabel: 'Select a Regional Branch'
}
);
processJSONVenue(
{
venueFilename: '/wp-content/uploads/recreational-venues.json', // JSON file name
venueCtrlId: 'recreationalVenue-ctrl', // ID of the drop-down
venueInfoId: 'recreationalVenue-info', // ID of the DIV placeholder to display the branch info
dropDownLabel: 'Select a Recreational Branch'
}
);
-
This reply was modified 9 months, 2 weeks ago by nomisrenrut.
-
This reply was modified 9 months, 2 weeks ago by nomisrenrut.