3
I found this project to insert TAGS in a form, but it only adds the TAG when enter key, and when it happens in my form it already sends! I would like to know what I should do in the SCRIPT so that it adds the TAG every time I insert comma or comma....
SCRIPT CODE:
<script>
$(document).ready(function() {
$('#addTagBtn').click(function() {
$('#tags option:selected').each(function() {
$(this).appendTo($('#selectedTags'));
});
});
$('#removeTagBtn').click(function() {
$('#selectedTags option:selected').each(function(el) {
$(this).appendTo($('#tags'));
});
});
$('.tagRemove').click(function(event) {
event.preventDefault();
$(this).parent().remove();
});
$('ul.tags').click(function() {
$('#tags-field').focus();
});
$('#tags-field').keypress(function(event) {
if (event.which == '13') {
if ($(this).val() != '') {
$('<li class="addedTag">' + $(this).val() + '<span class="tagRemove" onclick="$(this).parent().remove();">x</span><input type="hidden" value="' + $(this).val() + '" name="tags[]"></li>').insertBefore('.tags .tagAdd');
$(this).val('');
}
}
});
});
</script>
I can barely see your movements :p
– Jéf Bueno
@jbueno even though it took me a long time to find the tool kkkkk - However, like yours, it’s right.
– Bacco
I just found it strange that for me the code gave 191. Already gives AP a sense that this can be variable
– Jéf Bueno
Your keyboard is ABNT2?
– Bacco
Yes, it’s ABNT2. I was actually seeing this after I read your edition.
– Jéf Bueno
The browser itself can make a difference.
– Bacco
My friend, thank you for your help! I changed what you said and tested the codes on the tool you recommended, here it is 188 and 191... however it didn’t work! I insert the point and comma or comma and nothing happens, but I took the 13 that was enter and it’s not really adding by enter anymore!
– Igor Santana
I did not understand why there are quotes in the original code, I copied it as it was. Then test without. Anyway, I think the script chosen is a bit precarious. It would be good to see alternatives.
– Bacco
Bacco, thank you very much! I test now and it worked as follows: if (Event.which == 59 || Event.which == 188) { it separates when I put point and comma, already solve the problem!!! Vlwww!
– Igor Santana