pbuk
Science Advisor
Homework Helper
Gold Member
- 4,970
- 3,219
Again,
If you want to build it from vanilla HTML/JS then you will want something like this (I don't think you will need the id's any more):
[/CODE]
And then you can populate the HTML with something like:
This is based on the data for the declensions something like this:
Specifically I am referring to the concept of a ViewModel.pbuk said:This is exactly why dynamic JavaScript frameworks were developed. First Backbone and Knockout at the beginning of the last decade, then taken over by Google's Angular, Facebook's React and the independent Vue at the end.
If you want to build it from vanilla HTML/JS then you will want something like this (I don't think you will need the id's any more):
HTML:
<input type="text" data-cas="nomS"><input type="text" data-cas="nomP"><br><br>
<input type="text" data-cas="accS"><input type="text" data-cas="accP"><br><br>
<input type="text" data-cas="genS"><input type="text" data-cas="genP"><br><br>
<input type="text" data-cas="datS"><input type="text" data-cas="datP"><br><br>
<input type="text" data-cas="ablS"><input type="text" data-cas="ablP"><br><br>
And then you can populate the HTML with something like:
JavaScript:
const noun = nouns[selectedNoun];
document.querySelectorAll('[data-cas]').forEach((el) => {
const cas = el.dataset.cas;
// Can't remember if you can do it this way:
el.dataset.macron = noun[cas].macron;
el.dataset.plain = noun[cas].plain;
});
This is based on the data for the declensions something like this:
JavaScript:
const nouns = {
vis: {
nomS: { macron: 'vīs', plain: 'vis' },
accS: { macron: 'vīs', plain: 'vis' },
genS: { macron: 'vī', plain: 'vi' },
datS: { macron: 'vīm', plain: 'vim' },
ablS: { macron: 'vī', plain: 'vi' },
nomP: { macron: 'vīrēs', plain: 'vires' },
accP: { macron: 'vīrium', plain: 'virium' },
genP: { macron: 'vīribus', plain: 'viribus' },
datP: { macron: 'vīrēs', plain: 'vires' },
ablP: { macron: 'vīribus', plain: 'viribus' },
audioPrefix: './audio/vis-audio-',
},
terra: {
// ...
},
};