0

Hi I am trying to make a unique variable throughout my javascript.

I have >

var myfilename = "Report_Product_Daily";
var myfilename + spinner2 = $("<div id='spin1' class=\"activeSpinner\">\n\n<div id='spinborder1' class=\"spinner border1\"><\/div>\n\n<\/div>;");

The myfilename is the variable i want before all my variables.

Is this possible?

Mark

2
  • 1
    Note that this is almost always a bad idea. Commented Nov 10, 2015 at 9:38
  • What's wrong with a unique member of an array? Commented Nov 10, 2015 at 9:43

2 Answers 2

1

Yes, but you need somewhere to store it, possibly the window:

window[myfilename + 'spinner2'] = .....

or another object

var myObj = {};
myObj[myfilename + 'spinner2'] = .....
Sign up to request clarification or add additional context in comments.

Comments

0

You can do this:

var myVar = {},myfilename = "Report_Product_Daily";
myVar[myfilename + "spinner2"] = $("<div id='spin1' class=\"activeSpinner\">\n\n<div id='spinborder1' class=\"spinner border1\"><\/div>\n\n<\/div>;");

You CAN use the window object but it is considered polluting.

UPDATE: Perhaps THIS is what you want?

var Report_Product_Daily = {}
Report_Product_Daily["spinner2"] = $("<div id='spin1' ....

PS: This is better syntax:

$('<div id="spin1" class="activeSpinner"><div id="spinborder1" class="spinner border1"></div></div>;')

2 Comments

Thank you but what if i have lots of variables would i just do myvar[filename + spinner5] = blah blah;
yes with quotes. myvar[filename + "spinner5"] - for an alternative see update ....

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.