KheirEddine
KheirEddine

Reputation: 59

How to get values of jQuery Tags Input plugin

I use this jQuery Tags Input plugin:

jQuery Tags Input

but I can't get the values on my php file.

Upvotes: 5

Views: 11547

Answers (8)

Abd Abughazaleh
Abd Abughazaleh

Reputation: 5535

$("input").tagsinput('items')   

["Amsterdam","Washington","Sydney","Beijing","Cairo"]

$("input").val()    

"Amsterdam,Washington,Sydney,Beijing,Cairo"

Upvotes: 1

Maxime S.
Maxime S.

Reputation: 28

Based on sagivo answer you can write a function like this :

function getKeywords() {
  return $.map($('.tag span'),function(e,i){
    return $(e).text().trim();
  });
}

That will return an array of keywords present in the input. Like this [ "there", "it", "is" ]

Upvotes: 0

Steve P
Steve P

Reputation: 41

To get the list of emails from:

<input type="text" name="to_addresses" class="to_addresses" data-role="tagsinput" >

I use:

$emails = []
$.map($(".tagsinput span span"),function(e,i){
$emails.push($(e).text().trim());
})

Works for me, thought I'd share it.

Upvotes: 2

Sagiv Ofek
Sagiv Ofek

Reputation: 25270

using jquery you can do it in one line:

$.map($('.tag span'),function(e,i){return $(e).text().trim();})

Upvotes: 1

wang
wang

Reputation: 1

it change the hidden input value, and will post the data when you click submit , you can test it by a simple php script. print_r($_POST) to see it.

Upvotes: 0

Vishal Gavle
Vishal Gavle

Reputation: 367

 $("#btn").click(function () {
         var $tagWord = $("#tags_2").siblings(".tagsinput").children(".tag");
         var tags = [];
         for (var i = $tagWord.length; i--; ) {
             tags.push($($tagWord[i]).text().substring(0, $($tagWord[i]).text().length - 1).trim());
         }

         /*Then if you only want the unique tags entered:*/
         var uqTags = $.unique(tags);
         alert(uqTags.toSource());

     });

Upvotes: 1

Austin Floyd
Austin Floyd

Reputation: 306

If you are trying to get the individual values using jQuery you can use: (This is assuming the text input you made into a tag input has an id of "keywords")

$('#keywords').tagsInput({  
    'height':'auto',  
    'width':'350px',
    'defaultText':'',
    'delimiter': '|'
});
/*The delimiter option above overrides the default comma delimiter in the plugin allowing commas in tags if you prefer that...*/

var $keywords = $("#keywords").siblings(".tagsinput").children(".tag");  
var tags = [];  
for (var i = $keywords.length; i--;) {  
    tags.push($($keywords[i]).text().substring(0, $($keywords[i]).text().length -  1).trim());  
}  

/*Then if you only want the unique tags entered:*/  
var uniqueTags = $.unique(tags);  
alert(uniqueTags.toSource());

Upvotes: 7

FatherStorm
FatherStorm

Reputation: 7183

can you provide an example of what is POSTed? you can do so by pointing your form to go to api.fatherstorm.com?query and copying the json data that it gives you

Upvotes: 0

Related Questions