Search code examples
stringdoubleconcatenationquotes

Javascript: Error in String Concatenation


So I have this javascript function:

function show_courseline (course_index, repeats) {
var s = ""; 
var count = 0;
while (count < repeats) {
    s = s + 'Number: ' + document.getElementById(course_index + count + 'a').innerHTML + '\n' +
          'Semester: ' + document.getElementById(course_index + count + 'b').innerHTML + '\n' +
          'Year: ' + document.getElementById(course_index + count + 'c').innerHTML + '\n' +
          'Title: ' + document.getElementById(course_index + count + 'd').innerHTML + '\n' +
          'Units: ' + document.getElementById(course_index + count + 'e').innerHTML + '\n' +
          'Description: ' + document.getElementById(course_index + count + 'f').innerHTML + '\n';
    ++count;
}
alert(s);
}

But I get an error when I run it through an "onclick" input box. It has nothing to do with the document ids not being there, because they are.


Solution

  • Is course_index integer? If it is course_index + count is an integer and I know that ids cannot start with a digit