Jump to content

custom tag list


doddsey_65

Recommended Posts

im making a custom tag list where a user can enter tags into an input and seperate them with a comma. when they hit the comma key i want the name of the tag to be appended to a tag list. This is what i have so far but everytime a comma is inserted it adds all of the tags that are in the input field to the list rather than the one they have just added.

 

    $j('#post_tags').keyup(function(e){
        if(e.which == 188)
        {
            var tags = $j(this).val().split(',');
            var length = tags.length;
            $j(tags).each(function(i){
                $j('#tag_list').append(tags[i]);
            });
        }
    });

Link to comment
Share on other sites

The split() function will return an array of strings.

To get the last string in that array, use:

alert(tags[tags.length-1]);	

 

However, since you are using the comma key to fire up the script, that would probably give back an empty string as the last string in the array would be empty, so then you could also use:

alert(tags[tags.length-2]);	

 

Just experiment a bit to see what gives you exactly what you want.

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.