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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.