View Full Version : displaying input from a form
web_student
10-16-2008, 05:43 PM
I need a form that will allow users to input data and then display that input in another div. I already made the form, but I don't know the code to display that input after its been added. Security is not an issue, because the site is similar to an open blog.
Thank you in advance.
rangana
10-17-2008, 01:27 AM
Hope this basic example helps:
<script type="text/javascript">
function appendtoDiv(baseEl,targEl)
// Pass two params:
// 1 - The ID of the base element
// 2- The ID of target element
{
var p=document.createElement('p'); // Create a paragraph
// Create a text node to the created paragraph base on input's value
p.appendChild(document.createTextNode(document.getElementById(baseEl).value));
document.getElementById(targEl).appendChild(p); // Append the new paragraph to the target div
}
</script>
<input type="text" id="newinp"><input type="button" value="Add to Div" onclick="appendtoDiv('newinp','mydiv');">
<div id="mydiv" style="width:400px;padding:5px;border:1px solid #999;margin:10px;">
<h1>This is mydiv's content</h1>
<p>Another content</p>
</div>
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.