doddsey_65 Posted May 25, 2011 Share Posted May 25, 2011 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]); }); } }); Quote Link to comment https://forums.phpfreaks.com/topic/237430-custom-tag-list/ Share on other sites More sharing options...
BluB Posted May 26, 2011 Share Posted May 26, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/237430-custom-tag-list/#findComment-1220497 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.