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
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?

Link to comment
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.