Xtremer360 Posted January 17, 2011 Share Posted January 17, 2011 What I'm wanting to do is grab the Charactername of the first characterid in the CharacterIDList and I'm not sure with all the factors i have how to accomplish this. And after I get the name then assign in to var defaultchar in place of the ? mark. var defaultchar = ? var liElements = $("ul#characterlist li"); var characterIDList = ""; for( var i = 0; i < liElements.length; i++ ) { var liElement = $( liElements[ i ] ); // only start appending commas in after the first characterID if( i > 0 ) { characterIDList += ","; } // append the current li element's characterID to the list characterIDList += liElement.data( 'characterid' ); } function HandlerCharacters() { function isDupe(which) { var result = false; $('ul#characterlist li').each(function(i, e) { if ($(e).data('characterid') == which) { result = true; return false; // break out of .each() } }); return result; } var characterid = $('#charactersdrop option:selected').val(); var characterName = $('#charactersdrop option:selected').text(); if (characterid > 0 && !isDupe(characterid)) { // Create the anchor element var anchor = $( '<a href="#">Remove</a>' ); // Create a click handler for the anchor element anchor.click( function() { $( this ).parent().remove(); return false; // makes the href in the anchor tag ignored } ); // Create the <li> element with its text, and then append the anchor inside it. var li = $( '<li>' + characterName + ' </li>' ).append( anchor ); li.data( 'characterid', characterid ); // Append the new <li> element to the <ul> element $( '#characterlist' ).append( li ); } } Quote Link to comment https://forums.phpfreaks.com/topic/224731-getting-name-value/ Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.