Jump to content

Recommended Posts

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 );
        }
    }

Link to comment
https://forums.phpfreaks.com/topic/224731-getting-name-value/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.