I have a form with a textarea and list of tags from database( already queried and displayed under the textarea ) and want to add these tags (seperated by comma) on textarea and remove if the tag is already there as user click on them.
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I think I know what you mean, please have a look at this fiddle
http://jsfiddle.net/joevallender/QyqYW/1/
The code is below.
tagswould come from the server andselectedTagsis the managed array of current selections. you could load data from the server intoselectedTagstoo if necessary, if for instance editing an existing tagged post. If you did this, you’d refactor the code in theclick()function out to its own function so it could be run on document ready too.I’ve included some class toggling and a debug screen so you can see what is going on.
HTML
and JavaScript
EDIT Here is one that works in both directions http://jsfiddle.net/joevallender/QyqYW/14/