Saurabh Kumar
Saurabh Kumar

Reputation: 16671

Can't find the bug in javascript

Code:

for(int j=0; j<virtualFields.length();j++)
{
    finalOptions += '<option value="'+virtualFields[j]+'"><\/option>' ;   
}

Firebug is giving this error:

Missing ; after for loop initializer.

Upvotes: 1

Views: 180

Answers (2)

alex
alex

Reputation: 490607

You are using int to declare a variable.

Use var instead.

Also, if virtualFields is an Array, you should just be accessing the length property, not as a method.

Upvotes: -1

Gijs
Gijs

Reputation: 5262

Javascript doesn't understand int. Use var instead.

Some other pointers:

  • Assuming virtualFields is an ordinary array, length is a property, not a method.
  • You may need to html escape the virtualFields[j] values that you're concatenating like that.
  • You only need to escape / inside a regular expression, not within an ordinary string. So </option> would work just fine.

(these points are not related to the error, but you may wish to take them into account anyway)

Upvotes: 9

Related Questions