Jump to content

Preventing Duplicates wiht jquery


Xtremer360

Recommended Posts

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>

Link to comment
https://forums.phpfreaks.com/topic/220203-preventing-duplicates-wiht-jquery/
Share on other sites

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?

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.