0

Now I am developing a bar code based attendance system . Any there any javascript event can solve once the text field has detected the value has 10 characters, the text field will be fired and i can able to get the value.

Is there any solution ?

crchin
  • 9,473
  • 6
  • 22
  • 28

2 Answers2

2

I'm not sure what you mean by "the text field will be fired", but you can find out when the 10th character is entered by binding to the keyup event:

document.getElementById("example").onkeyup = function() {
    if(this.value.length === 10) {
        console.log("ok");  
    } 
};

It would be better to use addEventListener or attachEvent rather than setting the onkeyup property, but I'll leave that up to you.

Here's a working example.

James Allardice
  • 164,175
  • 21
  • 332
  • 312
  • So far, it can meet my requirement. but i have found out example as well. Here is the link : http://stackoverflow.com/questions/7105997/javascript-change-event-on-input-element-fires-on-only-losing-focus – crchin Feb 08 '12 at 08:06
  • @user1154655 - Yes, the accepted answer to that question is a good one. Be aware that it uses jQuery so you'll have to include it to use that answer as it is. – James Allardice Feb 08 '12 at 08:09
0

you can check the length of the text input box value on every keypress and make a function call when its the 10th character.

Abhidev
  • 7,063
  • 6
  • 21
  • 26