Results 1 to 2 of 2

Thread: DHTML ULs?

  1. #1
    Join Date
    Jan 2010
    Posts
    34

    DHTML ULs?

    I've come across a situation where I want my users to be able to make a dynamic list of things, and then commit the entire list to the database after they have finished making it.

    What I'd like to have is a simple text input field that had a button to the right of it that simply reads "Add". When the user enters input into the text field and clicks "Add", an unordered list somewhere else on the page loads a new bullet with the newly-added text input.

    The only problem is... I can't seem to figure out how to dynamically change lists. And, even more scary than that, from what I can collect, the HTML DOM doesn't even support this function!

    Here's my code:
    Code:
    <script type="text/javascript">
    function AddToList()
    {
        var newItem = document.getElementById("newItem").value;
    
        // if newItem = "Widget", then I need to add
        // <li>Widget</li> to the-list... but how?!?!
    }
    </script>
    
    <input type="text" id="newItem" size="30"/>&nbsp;
    <input type="button" value="Add" onClick="AddToList();"/>
    
    <p>
    
    <ul id="the-list">
    </ul>
    Thanks for any input

  2. #2
    Join Date
    May 2010
    Location
    Riverside, Ca
    Posts
    241
    Something like this:

    HTML Code:
    <script type="text/javascript">
    function AddToList()
    {
        var theList = document.getElementById("the-list");
        var newItem = document.getElementById("newItem".value;
        
        // Now append the innerHTML
        theList.innerHTML += "<li>"+newItem+"</li>";
    
    }
    </script>
    
    <input type="text" id="newItem" size="30"/>&nbsp;
    <input type="button" value="Add" onClick="AddToList();"/>
    
    <p>
    
    <ul id="the-list">
    </ul>
    Committing it to the database is a whole different story. Your best bet is to save each item into an array and then use AJAX to send it to a PHP page
    "The generation of random numbers is too important to be left to chance."

Similar Threads

  1. Anyone use DHTML Menu Builder?
    By junior_cjl in forum Client & Server Side Scripting (PHP, ASP, JavaScript)
    Replies: 0
    Last Post: 30 Jun 2010, 08:56 AM
  2. need help with DHTML
    By empeee in forum Web Design, HTML Reference and CSS
    Replies: 0
    Last Post: 01 Oct 2009, 01:44 PM
  3. dhtml menu appears too large in ie
    By adamros3 in forum Web Design, HTML Reference and CSS
    Replies: 0
    Last Post: 26 Mar 2009, 10:52 AM
  4. c# asp.net 2, dhtml, and javascript
    By maximummango in forum Client & Server Side Scripting (PHP, ASP, JavaScript)
    Replies: 0
    Last Post: 11 Jul 2006, 02:24 PM

Posting Permissions

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