1

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.

3
  • 3
    Wanna enlighten us with what the console is telling you? Is it just "syntax error" with absolutely no other information? My guess is the words "Unterminated String Literal" may be in there somewhere. :) Either way, you might consider starting by making sure each line ends with a ' + and begin 3,4,5, and 6 with a ' as not every editor can handle line-wrapping seamlessly. Commented Apr 2, 2012 at 1:00
  • Chrome says Uncaught SyntaxError: Unexpected token = in line 3 while safari says SyntaxError: Unexpected EOF Commented Apr 2, 2012 at 2:33
  • The issue was indeed a line-wrapping issue. I simply made it one line in text editor and that fixed it. Thank you. Commented Apr 2, 2012 at 2:37

1 Answer 1

3

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 + '"  />'
 );​
Sign up to request clarification or add additional context in comments.

Comments

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.