Results 1 to 2 of 2

Thread: displaying input from a form

  1. #1
    Join Date
    Oct 2008
    Posts
    1
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default displaying input from a form

    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.

  2. #2
    Join Date
    Feb 2008
    Location
    Cebu City Philippines
    Posts
    1,160
    Thanks
    17
    Thanked 277 Times in 275 Posts

    Default

    Hope this basic example helps:
    HTML Code:
    <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>
    Learn how to code at 02geek

    The more you learn, the more you'll realize there's much more to learn
    Ray.ph!

  3. The Following User Says Thank You to rangana For This Useful Post:

    web_student (10-20-2008)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •