get last word typed in Javascript -


i'm wondering how last word typed in javascript. have text area my_text , when user hits spacebar last word user typed. i'm trying far

function getlastword() {         var input = document.getelementbyid(my_text.value);         //var linein = document.getelementbyid(my_text).innerhtml;         var lastwordtyped         var changecolorofword;          if (input == null) {             input == " ";         }          lastwordtyped = input.substr(input.trim().lastindexof(" ") + 1); 

when function gets called on spacebar hit, says input null when gets lastwordtyped var, shows null , errors out, know why may happening?

preferably no jquery

here's of html go it.

<body> <br />  <!-- text area --> <textarea class="text_edit" id="my_text" onkeypress="return mykeypress(event)" onkeydown="return onkeydown(event)"></textarea> <br />  <!-- submit button --> <input type="button" value="run code" onclick="view_text()" />  <!-- empty div put text in --> <div id="view_text"> </div> 

ok, got error go away need change font color of word typed lol..

did mean

var input = document.getelementbyid("my_text").value; 

Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

jsf - How to ajax update an item in the footer of a PrimeFaces dataTable? -

django - CSRF verification failed. Request aborted. CSRF cookie not set -