开发者

How to get last entered number using jquery

开发者 https://www.devze.com 2023-04-04 08:49 出处:网络
I have the text box which only accepts number and dot so that i can enter deci开发者_C百科mal number.Also i need to get last entered value from that text. I used the following piece of code using onke

I have the text box which only accepts number and dot so that i can enter deci开发者_C百科mal number.Also i need to get last entered value from that text. I used the following piece of code using onkeypress event using java script

function only_numeric(e,val)
{
 var keynum;
 var keychar;
 var numcheck;
 if(window.event) // IE
 {
 keynum = e.keyCode;
 }
 else if(e.which) // netscape/Firefox/opera
 {
 keynum = e.which;
 }
 //condition for backspace(8) Key
 if(keynum != 8)
 {
 keychar = String.fromCharCode(keynum);
 //numcheck = /\d/;
 numcheck = /[.0-9]/;
 if(numcheck.test(keychar))
     {
        alert(keychar);
     }
 return numcheck.test(keychar);

 }
 else
 {
 return true;
 }
}

This one alert empty when i enter first number then again if i entered second it alert first number, finally i missed last value .I am calling only_numeric function on 'onkeypress' kindly help me on this.


I suggest you to use onkeyup. Check below code

$(selector).keyup(function() {
var textValue = $(this).val();
DoX();
});

 or

  $(document).ready(function() {
    $("#field").keypress(function(event) {
        alert(event.charCode);
    });
});

Or

check this code and implement it in your code.

$("input[x]").keypress(function (e) {
var c = String.fromCharCode(e.which);
//process the single character or
var textValue = ("input[x]").val();
var fulltext = textValue + c;
//process the full text

});

0

精彩评论

暂无评论...
验证码 换一张
取 消