Using the html and Javascript below I count the number of characters entered in an input field and limit them to 30. I also show a counter to the user.

The counter changes its value on this events: `onfocus`, `onKeyDown`, `onKeyUp`, `onpaste`.

I can't get `onpaste` to work. The counter changes value when user pastes using "CTRL V" but not when pasting using mouse / right click. What am I doing wrong?

**Jsfiddle:** <https://jsfiddle.net/ow3ubgp0/>

**HTML:**

```
<input readonly type="text" name="countdown1" size="5" value="30" />

<input type="text" id="my_text_input" name="my_text_input" onfocus="limitText(this.form.my_text_input,this.form.countdown1,30);" onKeyDown="limitText(this.form.my_text_input,this.form.countdown1,30);" onKeyUp="limitText(this.form.my_text_input,this.form.countdown1,30);" onpaste="limitText(this.form.my_text_input,this.form.countdown1,30);" />

```

**Javascript:**

```
function limitText(limitField, limitCount, limitNum) {
    if (limitField.value.length > limitNum) {
        limitField.value = limitField.value.substring(0, limitNum);
    } else {
        limitCount.value = limitNum - limitField.value.length;
    }
}

```