Reputation: 5283
I have got a simple input tag
<input type="text" id="textb" name="textbox"/>
jquery is
$("document").ready(function(){
$("#textb").live("keyup",function(){
alert($(this).val());
//this gives me complete value inserted by user
})
})
the question is that i want to get only the last value inserted by user if user enter ("hello"),Than it should show alert("o")
Upvotes: 1
Views: 1363
Reputation: 941
I recommend putting the output in a div as it is more user friendly.
$( document ).ready( function() {
$( 'input' ).keyup( function( evt ) {
var val = $( this ).val(),
newVal = val.substr( -1, 1 );
$( '#output' ).empty();
$( '#output' ).html( newVal );
});
});
or see the user friendly version here http://jsfiddle.net/wh1t3w0lf21/pUNXD/
Upvotes: 0
Reputation: 1201
You could update to this:
alert($(this).val().substr($(this).val().length-1));
Upvotes: 1
Reputation: 144689
try this:
$("#textb").live("keyup",function(){
alert($(this).val().slice(-1));
})
or:
$("#textb").on("blur",function(){
alert($(this).val().slice(-1));
})
Upvotes: 2
Reputation: 365
jQuery("document").ready(function($){
$("input").bind("keyup",function(e){
alert(String.fromCharCode(e.keyCode));
});
});
Upvotes: 2