0

This is my code.... It is not working in the way it should and at the same time it is not showing any errors in the console....

In the following code, I want that when the users submit their entry, the entry should become a part of an array and add a greeting before the name, All the entries should be placed in separate paragraphs under the input and greeting... Can anyone please help me and tell me how to fix this..... <!DOCTYPE html> <html> <head> <title>Javascript</title> </head> <body> <input type="text" id="textInput"> <button id="button">Submit</button> <p id="text"></p> <script type="text/javascript"> var names = new Array(); var qOfNames = names.length; document.getElementById("button").onclick = function() { document.getElementById("text").innerHTML = "Hello " + document.getElementById("textInput").value; document.getElementById("textInput").value = ""; names[qOfNames++] = document.getElementById("textInput").value; var data = document.createElement("p"); var dataEntry = document.createTextNode(toString(qOfNames) + "- " + names[qOfNames]); data.appendChild(dataEntry); } </script> </body> </html>

27th Apr 2020, 2:08 PM
KASH
KASH - avatar
1 Réponse
0
<script type="text/javascript"> var names = new Array(); document.getElementById("button").onclick = function() { var qOfNames = names.length ; names.push( document.getElementById("textInput").value); document.getElementById("textInput").value = ""; var data = document.createElement("p"); var dataEntry = document.createTextNode(qOfNames + "- " + names[qOfNames]); data.appendChild(dataEntry); document.getElementById("text").appendChild(data); } </script>
27th Apr 2020, 2:54 PM
yochanan sheinberger
yochanan sheinberger - avatar