Pregunta

I am trying to use a variable of a textareas value but I don't want the entire value only the new word that is being written.

What I've tried doing is something like this-

function getValue(ele,array){
 var a = ele.val();
 array.push(a);
}
function newWord(ele,array){
 var b =ele.val();
 array.toString.match(b);
}

   $(function() {
      $('#textarea').keyup(function() {
         var array = [];
      getValue($(this),array);
      console.log(array);
      var c = newWord($(this),array);
        console.log(c);
     });
    });

What I was hoping for is that it would get the newly typed word. All I want to do is get that new word that is being typed up until a space is entered. And I was working with a few plugins that would getSelection for all modern browsers and well that just didn't work for me as well.

Does anyone have a suggestion on the best way to do this? I don't mind on keep trying myself just need a little hand to lead me on the right path to get my full code working the way I need it to. Full Code is here http://jsbin.com/obihig/1/edit it is a Auto Suggestion, for textarea, and it needs to be for every word being written.

¿Fue útil?

Solución

$(function() {
  $('#textarea').keyup(function() {
     var array = [];
     var newWord;
     array = this.val().split(' ');
     console.log(array);
     newWord = array[array.length - 1]
     console.log(newWord);
 });
});
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top