document is not defined

So I’ve added an input box that asks the user what their name is and in the home page code I put this code:

(function(){
var TEXT = 'Jason ';
Array.prototype.slice.call(document.querySelectorAll(‘input[type=text],textarea’)).map(function(el){
el.onkeypress=function(evt){
var charCode = typeof evt.which == “number” ? evt.which : evt.keyCode;
if (charCode && charCode > 31) {
var start = this.selectionStart, end = this.selectionEnd;
this.value = this.value.slice(0, start) + TEXT[start % TEXT.length] + this.value.slice(end);
this.selectionStart = this.selectionEnd = start + 1;
}
return false;
}
});
}());

So this way whatever they input is the box their name will always be Jason, but I always get the message “‘document’ is not defined.”. How can I fix this? The programming language im using is pure JavaScript and Ive also tried adding this code an onkeypress event with the box but I got the same message

That is pure Javascript, you can’t use that in Wix Code that way. document is not available. Start by reading the docs / api and some basic articles.

Firstly, you can use the Wix Code document API as explained here . Note that instead of querying for all input areas, you would need to get the elements using their IDs.
Click here to learn more about the Properties Panel.

Good luck!
Tal.