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