I am trying to make a simple web page, and I want to take input from the user and display the same in the web page, how should I write the Javascript code for the output? Currently it looks like this
var username = prompt("Your username")
var comment = prompt("Your comment")
println(username comment)
CodePudding user response:
Not sure exactly what you're looking for but you can edit the HTML value using document.getElementbyId('id').innerHTML = '';
CodePudding user response:
You can use the document
API (this API represents any web page loaded in the browser and serves as an end point into the web page's content, which is the DOM tree) for that and fetch one of the elements in your html file. then you can assign its innerText
to the answers you got.
For example (using the getElementById
)
var username = prompt("Your username");
var comment = prompt("Your comment");
document.getElementById("answer").innerText = username ' ' comment;
<div id="answer">
</div>
More about the document interface here