Xtremer360 Posted November 30, 2010 Share Posted November 30, 2010 The idea here is I want it to be able to when a li is dropped down into the ul to make sure that there is no match to it. I'm wanting to prevent duplicates. <script type="text/javascript" language="javascript"> // Long version function HandlerCharacters() { var characterid = $('#charactersdrop option:selected').val(); var characterName = $('#charactersdrop option:selected').text(); if( characterid > 0 ) { // 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 ); } } </script> Quote Link to comment Share on other sites More sharing options...
Adam Posted December 1, 2010 Share Posted December 1, 2010 See if this helps: $('#characterlist').children('li').each(function() { if ($(this).text() == li.text()) { return false; } }); Quote Link to comment Share on other sites More sharing options...
Xtremer360 Posted December 1, 2010 Author Share Posted December 1, 2010 However I'm thinking instead of the text I'm going to need the values for my database instead. Is it safe under this line: li.data( 'characterid', characterid ); And one more thing with my array, I need the first listed value separated for my php process page. Do I need to do that with jquery first? Quote Link to comment 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.