I can't seem to return an object from a function, the console.log inside the function prints out the property values fine but once outside the function I'm getting "Uncaught ReferenceError: firstOn is not defined"
Any help would be appreciated, thanks!
myElement = document.getElementById("testButton");
function Server(name,tables,startTime) {
this.name = name;
this.tables = tables;
this.startTime = startTime;
}
document.forms.server1.button.onclick = function() {
var name = document.forms.server1.servername.value;
var tables = document.forms.server1.servertables.value;
var startTime = document.forms.server1.servertime.value;
var firstOn = new Server(name,tables,startTime);
document.forms.server1.button.innerHTML = "Saved!";
console.log(firstOn.name);
console.log(firstOn.tables);
console.log(firstOn.startTime);
return firstOn;
};
myElement.onclick = function() {
console.log(firstOn.name);
console.log(firstOn.tables);
console.log(firstOn.startTime);
};
var