Click here to Skip to main content
16,021,125 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,

I know I can reproduce what is written in input boxes in other input boxes --- like with "shipping" and "billing" addresses.

However, I haven't been able to make it so I can present that entered data somewhere else - like when people enter data on a website and then there answers show up in "Settings."

What I have tried:

I tried adding: "document.getElementById("text").value=(shippingZip.value);"

to a function --- with "<p id="text"></p>" in the HTML

But that didn't work.

Any help would be appreciated.

Best,
Matt
Posted
Updated 28-Oct-19 17:47pm

1 solution

Paragraph tag does not have "value" attribute like input tags.

You can use "textContent" below is an example code on how to use it.

HTML
<!-- SWAMI KARUPPASWAMI THUNNAI -->

<!DOCTYPE html>
<html>
<head>
	<title>Javascript Example</title>
	<script type="text/javascript">
		// Changes text from the input box to paragraph
		function changeText()
		{
			let text_value = document.getElementById("input_box").value;
			document.getElementById("text").textContent = text_value;
		}
	</script>
</head>
<body>
	<p id="text">You will see the changed text here<br/></p>
	<input type="text" name="input_box" id="input_box">
	<button type="button" onclick="changeText();">CHANGE TEXT</button>
</body>
</html>


function changeText will take the value from input and sets it into paragraph tag. You may run the code in your browser for better understanding.

Warning: Do not use innerHTML for this purpose, it may seem to work but inputs like

XSS

may lead cross site scripting vulnerability.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900