Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Jun 2008
    Posts
    682
    Thanks
    114
    Thanked 2 Times in 2 Posts

    Not Adding Value To UL

    Nothing happens when the button is clicked to add a new character name to the UL.

    This is in my ajax.js
    PHP Code:
    function WrestlerList()
    {
    var 
    addWrestler document.getElementById("character_selection").value
    if (addWrestler) {
    // Here we append a new wrestler to your hidden field using a comma
    document.getElementById("chars").value += addWrestler+",";
    // Continue your original functionality
    document.getElementById("characterlist").innerHTML += "<li>" +
    addWrestler "</li>";
    return 
    WrestlerList;
    }

    backstagefunctions.php
    PHP Code:
    print '<script type="text/javascript" src="ajax.js"></script>';
       print 
    '<h2 class="backstage">Characters<br /><br />';
       print 
    '<select name="characterid" class="dropdown" id="character_selection">';
       print 
    '<option value="">- Select -</option>';
       
    $query 'SELECT charactername FROM characters';
       
    $result mysql_query $query );
       while ( 
    $row mysql_fetch_assoc $result ) ) {
          print 
    "<option value=\"".$row['charactername']."\">".$row['charactername']."</option>\r";
       }
       print 
    '</select>&nbsp;&nbsp;<input type="hidden" id="chars" name="chars" value=""><input type="button" value="Add" onclick="WrestlerList()" class="button"></h2><br />';
       print 
    '<ul id="characterlist"></ul><br /></form>'

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,849
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    Could you post a link to your page(or a sample one)? Or post your complete parsed output (html+javascript) taken from browser's view source option.
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #3
    Senior Coder rangana's Avatar
    Join Date
    Feb 2008
    Location
    Cebu City, Philippines
    Posts
    1,752
    Thanks
    65
    Thanked 372 Times in 365 Posts
    I don't see any AJAX functionality on your page. This is just a JS.

    Reading your code, I'm assuming that you are wanting to expand the list of your characterlist ul element base on the value of selected of character_selection select element.

    The problem at your end is that you're using innerHTML to create the list.

    I suggest you do this via DOM.

    You can make use of createElement() property, and appendChild() to append the new list.

    With that said, try this instead:
    Code:
    function WrestlerList(){
    	var addWrestler = document.getElementById("character_selection").value
    	if (addWrestler){
    		// Here we append a new wrestler to your hidden field using a comma
    		document.getElementById("chars").value += addWrestler+",";
    		// Continue your original functionality
    		var li = document.createElement('li'); // Create a list
    		li.innerHTML = addWrestler; // Let the value be the value of the dropdown
    		document.getElementById("characterlist").appendChild(li); // Append to our UL element
    	}
    }
    Hope that helps, this is untested, but the logic might work.
    Learn how to javascript at 02geek

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


  •  

    Posting Permissions

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