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?
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

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.
You could use eval().
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


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.