Looking online I found an example of a javascript code that updates HTML based on one text field.
Dynamically displaying input values using Javascript
That page links to this example. https://jsbin.com/ugasi5/3/edit?html,js,output
In the spirit of making it work before making it better.
I tried to extend it to more than one filed by creating duplicate variables (with unique names) it doesn't output anything. Also and it is clearly a naive attempt to make more than one field.
So my question is what is a non-naive way to extend this code for more than one (N) inputs?
HTML
<body>
<form>
<input type='text' id='nameField'>
</form>
<hr> Your name is <span id='nameDisplay'>??</span>
</body>
Javascript
window.onload = function() {
var nameField = document.getElementById('nameField');
var lastNameValue = undefined;
updateNameDisplay();
setInterval(updateNameDisplay, 100);
function updateNameDisplay() {
var thisValue = nameField.value || "??";
if (lastNameValue != thisValue) {
document.getElementById('nameDisplay').innerHTML = lastNameValue = thisValue;
}
}
};
Edit in response to @heretic-monkey for the context of and objectionable measurable definition writing a non-native procedure. A Navie method of creating N inputs would have lots of code duplication, where a non-naive method would likely use loop patterns and have less code duplication. than a non-naive method. For example.
In pseudo a naive procedure:
create input 1
create input 2
create input 3
...
create input N
create output 1
create output 2
create output 3
...
create output N
In pseudo a non-naive procedure:
someLoopPattern
create N inputs
someLoopPattern
create N outputs