I'm in the middle of making a user registration form and want to prevent pasting into certain input boxes. Problem is, onPaste isn't being recognized as an event.
As you can see in this image, onKeyPress is being recognized, whereas onPaste is not.
After some Googling it seems I am the only person on the planet who has encountered this (which probably means it's something silly and I'm a massive idiot). I'm using NetBeans IDE 8.2. Thanks in advance for any help.
onPaste not recognized as event by HTML5
557 Views Asked by The Lads At
3
There are 3 best solutions below
2
On
Try using onpaste instead of onPaste as it shows on the w3c example page. and what is the IDE are you using? try using a different syntax highlighting add-in or a plugin.
0
On
function preventPasting(id) {
console.log(id);
}
<input type="password" class="form-control" maxlength="50" id="password" onpaste="preventPasting(this.id)">
Change 'onPaste' with 'onpaste', maybe like this code.
For more documentation of onpaste : https://www.w3schools.com/jsref/event_onpaste.asp
Oops! As I suspected, I was being a massive idiot. onPaste doesn't appear to be recognized as an event in my IDE, but on run-time it will actually fire. My JavaScript code for the event was flawed and this is why nothing was happening.
Thanks for the help all.