Reputation: 59
I use this jQuery Tags Input plugin:
but I can't get the values on my php file.
Upvotes: 5
Views: 11547
Reputation: 5535
$("input").tagsinput('items')
["Amsterdam","Washington","Sydney","Beijing","Cairo"]
$("input").val()
"Amsterdam,Washington,Sydney,Beijing,Cairo"
Upvotes: 1
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
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
Reputation: 25270
using jquery you can do it in one line:
$.map($('.tag span'),function(e,i){return $(e).text().trim();})
Upvotes: 1
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
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
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
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