jQuery Syntax

I have a question about jQuery Syntax.  I am using a CMS that has a tag {row_id} that, of course echos out the row id.  In my jQuery, I am referencing the row ID.  In my code I have this:
	var formUpdate_{row_id} = function() { 

Open in new window

in In my development IED this line gives me an error.  Is there a way to escape this and still have it work so the error is gone?
LVL 7
rgranlundAsked:
Who is Participating?
 
skijCommented:
I tested the following code and it works for me.

var row_id = '{row_id}';
if (row_id.substr(0,1)=='{') row_id = '1';
var line1 = 'var formUpdate_'+ row_id +' = function(){';
var line2 = 'alert(123);';
var line3 = '}';
eval(line1 + line2 + line3);

Open in new window

0
 
Robert SchuttSoftware EngineerCommented:
Depending on the placement of this code and the scope you need the variable(s) to be in you might be able to use:
window['formUpdate_{row_id}'] = function() {

Open in new window

or
this['formUpdate_{row_id}'] = function() {

Open in new window

That should be valid code for the IDE and with a bit of luck your CMS does the replace regardless of the fact that the tag is now in a javascript literal.
0
 
skijCommented:
You could use eval().
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.