0

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.

2
  • 1
    What error messages do you get? Your second example works. Commented May 8, 2013 at 20:31
  • Oops, nevermind, the second example erred on something else. Commented May 8, 2013 at 20:39

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

3 Comments

Wow, that actually worked! Thanks! So why can't ID's start with digits?
It is related to the languages' grammar and compiler issues. Most of the programming languages are designed in such a way.
@zitta: This isn't completely correct. In HTML5, the only restrictions on id are uniqueness and consisting of one or more characters that aren't spaces.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.