...

View Full Version : Not Adding Value To UL



CoolAsCarlito
01-23-2009, 06:25 PM
Nothing happens when the button is clicked to add a new character name to the UL.

This is in my ajax.js

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

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>';

abduraooft
01-24-2009, 08:42 AM
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.

rangana
01-24-2009, 08:56 AM
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:


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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum