mistersoftee
mistersoftee

Reputation: 93

jQuery SyntaxError: Unexpected token =

I am trying to pass a bunch of variables to a hidden input value but I am getting a stupid syntax error in this code:

$('#imgdata').append(   
    '<input type="hidden" name="imgdata[' + id + '][width]" value="' + _width + '"/>
     <input type="hidden" name="imgdata[' + id + '][height]" value="' + _height + '"  />
     <input type="hidden" name="imgdata[' + id + '][left]" value="' + _left + '"  />
     <input type="hidden" name="imgdata[' + id + '][top]" value="' + _top + '"  />
     <input type="hidden" name="imgdata[' + id + '][src]" value="' + _src + '"  />'
 );

I must be overlooking a simple syntax mistake. Console tells me its in 3rd line.

SOLUTION:

The issue was with the line-wrapping. Making the code inline without pressing enter for formatting fixed it.

Upvotes: 1

Views: 801

Answers (1)

iambriansreed
iambriansreed

Reputation: 22261

JavaScript string lines must be end with \. Besides that make sure all the variables are indeed defined.

You code sample should be as follows:

$('#imgdata').append(   
    '<input type="hidden" name="imgdata[' + id + '][width]" value="' + _width + '"/>\
     <input type="hidden" name="imgdata[' + id + '][height]" value="' + _height + '"  />\
     <input type="hidden" name="imgdata[' + id + '][left]" value="' + _left + '"  />\
     <input type="hidden" name="imgdata[' + id + '][top]" value="' + _top + '"  />\
     <input type="hidden" name="imgdata[' + id + '][src]" value="' + _src + '"  />'
 );​

Upvotes: 3

Related Questions