javascript - Remove last character on input field jQuery -


i know kind of question has been asked several times none of answers worked me. want make own spell-checker compares words letter letter , checks correctness. user types letters 1 one, content checked. if correct, goes on, if wrong: want last letter deleted.

here code:

var word = []; word = "beautiful".split(''); var =0;  $(document).ready( function()  { $('#txtword').keyup(  function() {     var value = document.getelementbyid('txtword').value;     if (value[i] == word[i]){              alert("right letter!");             i++; }             else             { alert("wrong letter");             value.slice(0,-1);             /*value.substr(0,value.length-1);*/             }         });     }) 

i tried both options value.slice(0,-1); , value.substr(0,value.length-1); not working. can me find mistake!

you need assign new value value property of element

this.value = value.substr(0,value.length-1); 

note: can use this.value instead of document.getelementbyid('txtword').value;


Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

css - Firefox for ubuntu renders wrong colors -