I want a user to input their top ten favourite movies, each in a separate text input field. As they type in a box, a 'onkeyup' event triggers a JS function, which makes what they are typing reappear directly below where they are typing.
Do I have to write out ten different JS onkeyup functions for each box, or is there a relatively straightforward way that a single function can do the job, via the means of variables or somesuch?
Maybe this make things clearer:
HTML
<form id="movie1">
<h3>Your favourite movie</h3><br><br>
Type the name of your favourite movie: <input type="text" name="name" maxlength="50" onkeyup="inputMovieOne()">
<p>Your favourite movie:<span id=movie1goeshere></span><span></p>
</form>
<form id="movie2">
<h3>Your second favourite movie</h3><br><br>
Type the name of your second favourite movie: <input type="text" name="name" maxlength="50" onkeyup="inputMovieTwo()">
<p>Your second favourite movie:<span id=movie2goeshere></span><span></p>
</form>
...and so on eight more times...
JS
<script>
function inputMovieOne() {
var x = document.getElementById("movie1").elements.namedItem("name").value;
document.getElementById("movie1goeshere").innerHTML = x;
}
function inputMovieTwo() {
var x = document.getElementById("movie2").elements.namedItem("name").value;
document.getElementById("movie2goeshere").innerHTML = x;
}
</script>
...and so on eight more times...