Reputation: 741
In the code below I have an array_push() command where it stores data in the necessary columns:
$studentInfo = array();
while ( $studentqrystmt->fetch() ) {
$studentData = array();
$studentData["StudentId"] = $dbStudentId;
$studentData["StudentDOB"] = $dbStudentDOB;
$studentData["StudentYear"] = $dbStudentYear;
$studentData["CourseNo"] = $dbCourseNo;
$studentData["CourseName"] = $dbCourseName;
array_push($studentInfo, $studentData);
Now what I am trying to do with the jquery code below is that I store the necessary data from each column into the desired text inputs by using the text input ids. Now the code below works for DOB and Year being stored in their text inputs:
$('#studentsDrop').change( function(){
var studentId = $(this).val();
if (studentId !== '') {
for (var i = 0, l = studentinfo.length; i < l; i++)
{
if (studentinfo[i].StudentId == studentId) {
var currentdob = $('#currentStudentDOB').val(studentinfo[i].StudentDOB);
var currentyear = $('#currentStudentYear').val(studentinfo[i].StudentYear);
break;
}
But the line below does not work when I try to include it in the function above;
var currentcourse = $('#currentStudentCourse').val(studentinfo[i].CourseNo." - ".studentinfo[i].CourseName);
With the line above what I am trying to do is display the CourseNo and CourseName in one text input separated with a -
in between. But when trying to do this I end up with an error stating:
SyntaxError: missing name after . operator
The error is pointing to that line of code. My question is how can fix error be fixed by being able to display both CourseNo and CourseName into the single text input '#currentStudentCourse'
?
Upvotes: 0
Views: 52
Reputation: 22007
In JavaScript, you should use the +
operator to concatenate strings:
var currentcourse = $('#currentStudentCourse').val(studentinfo[i].CourseNo + " - " + studentinfo[i].CourseName);
Upvotes: 2