When a button is clicked, takes text that a user has entered in an input box and
ID: 3607734 • Letter: W
Question
When a button is clicked, takes text that a user has entered in an input box and then places this text somewhere else on the webpage.
You first need to add the necessary HTML elements for the JS to reference (i.e. button and input)
This is what it is suppose to entail but I cannot arrange it correctly
<input type="text" size="50" id ="in"/>
id="user"
<button>
click to add content
x ="userPage()"
</button>
<script type ="text/javascript">
function userPage(){
var x;
x =document.getElementById("in").value
>
}
</script>
Explanation / Answer
<html>
<head>
<script type ="text/javascript">
function userPage()
{
var x;
x = document.getElementById("in").value;
document.getElementById("user").innerHTML=x;
}
</script>
<title>
Webpage
</title>
</head>
<body>
<input type="text" size="50" id ="in"/>
<p id="user"></p>
<button>click to add content</button>
</body>
</html>
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.