Jump to content

this.value = one letter behind?


GuitarGod

Recommended Posts

Hi all,

 

I'm having a little problem with JS's "this.value" - it always seems to be one letter behind than the fields actual value. If I may explain:

 

<input type="text" onkeydown="alert(this.value)">

 

As you can see, everytime a key is entered, the value of the text box should be displayed in a Javascript alert. However, if I entered the letter "M", then a blank JS alert would pop up. If I enter another letter along side the "M", for example "D", then the letter "M" would alert, but not the "D". If I entered a third letter, then the letters "MD" would alert, but not the third letter. So the alert message is always one letter behind.

 

I hope you can understand what I mean. Is there anyway round this so the exact value that I enter is the value that gets alerted?

 

Thanks for any light you can shed on this.  ;)

Link to comment
https://forums.phpfreaks.com/topic/213064-thisvalue-one-letter-behind/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.