I've been struggling with this bit of code for quite a few days. Essentially it's an object that takes the input of 3 text boxes and concatenates them into a string.. or that's what it should do.
Student.toString returns as undefined or "Uncaught TypeError: Property 'Student' of object [object Object] is not a function" when it should be last name, first name and then id number. Can anybody explain what I did wrong on this?
<div id='textInside'>
First Name:<input type='text' id='fName'><br>
Last Name:<input type='text' id='lName'><br>
Student Id: <input type='text' id='stuId'><br>
<button onclick='readInputs()'>Update</button>
<p id='stuInfo'></p>
</div>
<script type='text/javascript'>
var fiName = document.getElementById('fName');
var laName = document.getElementById('lName');
var studeId = document.getElementById('stuId');
var toP = document.getElementById('stuInfo');
var Student = new Object;
function Student() {
this.firstName = fiName;
this.lastName = laName;
this.studentId = studeId;
this.toString = function() {var result = toP.innerHTML = this.lastName + this.firstName + this.studentId};
return result;
this.readInputs = function() { };
}
function readInputs() {
Student();
Student.toString();
}
</script>