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
https://forums.phpfreaks.com/topic/237430-custom-tag-list/
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
https://forums.phpfreaks.com/topic/237430-custom-tag-list/#findComment-1220497
Share on other sites

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.