0

I've recently got the tag-it jquery successfull working on my site, there is a text area for the users to put in their own tagss, then a textarea, ie.

[ dog ] [ park ] [ weekend ]

Taking the dog to the park this weekend with Bill!

[Post]

I've been trying to google search this for hours with no results, so I am wondering if anyone on here has been able to tweak with the code, or you know of somewhere you could link me to, so that the user only needs to fill in the text area..

Taking the dog to the park this weekend with Bill!

Then on submission it generates tag words off the text area, with inclusions such as..

var tags = $('#message').val().split(' '); 
var excludeWords = ['took','the','a','to']; 
tags.filter(function (element, index, array) 
{ return ($.inArray(element, excludeWords) === -1); });
user2571547
  • 87
  • 1
  • 1
  • 9
  • what output you want ??? – Tushar Gupta - curioustushar Jul 24 '13 at 07:17
  • I'm trying to see if I can get it so that I can just have a textarea and the tags are generated based on the words and submitted in 1 go, so you could type "disneyland was fun" with was under exclusions, so it would automatically create the tags "disneyland" and "fun". Make sense? – user2571547 Jul 24 '13 at 07:20

1 Answers1

0

Working Demo http://jsfiddle.net/cse_tushar/U94Le/

$('#b').click(function () {
    tags = $('#message').val();
    tags = tags.replace(/!/g, '');
    var excludeWords = ['took', 'the', 'a', 'to', 'with', 'dog', 'this'];
    $.each(excludeWords, function (i, v) {
        pos = tags.indexOf(excludeWords[i]);
        while (pos > -1) {
            tags = tags.replace(" " + excludeWords[i] + " ", ' ');
            pos = tags.indexOf(excludeWords[i], pos + 1);
        }
    });
    console.log(tags);
    tags = tags.split(' ');
    console.log(tags);
    $('#output').html('<pre>' + tags + '</pre>');
});
Tushar Gupta - curioustushar
  • 58,085
  • 24
  • 103
  • 107
  • Wow very nice, will that be difficult to alter to submit to the "action=" element of the form instead of posting to a visual display(result)? – user2571547 Jul 24 '13 at 08:34
  • no it will not be difficult just make an hidden input filed pass this value to it and then submit the form. – Tushar Gupta - curioustushar Jul 24 '13 at 08:48
  • Ok I am setting up to test the code now, I'm wondering if logically it will work just because right now the tags are $tags, and the text box is $topic_data, I'm not sure if I can code it so that it parses the tags though, and posts the data into topic_data, sorry I'm very new to php/mysql and even newer to js – user2571547 Jul 24 '13 at 08:55