I am trying to make a page that shows one word at a time for 5 seconds from an array of values. On this page is also a form with one input field into which people enter their attempt to spell that word.
I would like to capture the results of the values entered in the field in an object that contains
- the user entered value and the correct answer (i.e. the value shown in the
spellingsarray below) - the number of correct answers
- an array of the incorrect answers
and post this back to the application
So far I have the below but it's not even looping through the array correctly. Also I guess I need to dynamically update the form input so I know which attempt related to which word.
<script>
var spellings = ['first', 'second', 'third', 'fourth', 'fifth'];
setInterval(function() {
for (var i=0; i<=spellings.length; i++){
document
.getElementById('spellings')
.innerHTML = spellings[i];
}
}, 1000);
</script>
and the HTML
<span id="spellings"></span>
<form action="/spellings" method="POST">
<div class="form">
<label for="spelling">spelling</label>
<input type="text" class="form-control" id="spelling" name="spelling">
<button type="submit" class="btn btn-primary">Submit</button>
</form>
Edit - some more context as requested in comment below
In the <span id="spellings"></span> I would like to show for 5 seconds each item in the spellings array.
In the form that is shown underneath each word I would like to capture the user's input and ultimately POST this back to the application
Any help on how to do this would be great
.innerHTMLit should bevaluesecond of all you should no usegetElementByIdin afor- loop ... is a performance issue. And lastly, what excatly is the problem that should be solved? Could you add some more context?