Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

What's wrong with this loop.... 1

Status
Not open for further replies.

fooobee

Technical User
Nov 13, 2003
33
US
I wrote a loop to replace repetive source code. It doesn't seem to work,

I wrote this:

Code:
	for (count=0; count <=8; count ++) {
		this.item_text_color_roll0_ + [count] =  "#5f5f5f"
		this.item_font_family0_ + [count] = "Verdana";
       		this.item_font_family_roll0_ + [count] = "Verdana";
        	this.item_font_weight0_ + [count] = "normal";
        	this.item_font_weight_roll0_ + [count] = "normal";
        	this.item_font_style0_ + [count] = "normal";
        	this.item_font_style_roll0_ + [count] = "normal";
        	this.item_font_size0_ + [count] = "11px";
        	this.item_font_size_roll0_ + [count] = "11px";
	}

to replace this:

Code:
        this.item_text_color_roll0_0 = "#5f5f5f"
        this.item_font_family0_0 = "Verdana"
        this.item_font_family_roll0_0 = "Verdana"
        this.item_font_weight0_0 = "normal"
        this.item_font_weight_roll0_0 = "normal"
        this.item_font_style0_0 = "normal"
        this.item_font_style_roll0_0 = "normal"
        this.item_font_size0_0 = "11px"
        this.item_font_size_roll0_0 = "11px"
        this.item_text_color_roll0_1 = "#5f5f5f"
        this.item_font_family0_1 = "Verdana"
        this.item_font_family_roll0_1 = "Verdana"
        this.item_font_weight0_1 = "normal"
        this.item_font_weight_roll0_1 = "normal"
        this.item_font_style0_1 = "normal"
        this.item_font_style_roll0_1 = "normal"
        this.item_font_size0_1 = "11px"
        this.item_font_size_roll0_1 = "11px"
        this.item_text_color_roll0_2 = "#5f5f5f"
        this.item_font_family0_2 = "Verdana"
        this.item_font_family_roll0_2 = "Verdana"
        this.item_font_weight0_2 = "normal"
        this.item_font_weight_roll0_2 = "normal"
        this.item_font_style0_2 = "normal"
        this.item_font_style_roll0_2 = "normal"
        this.item_font_size0_2 = "11px"
        this.item_font_size_roll0_2 = "11px"
        this.item_text_color_roll0_3 = "#5f5f5f"
        this.item_font_family0_3 = "Verdana"
        this.item_font_family_roll0_3 = "Verdana"
        this.item_font_weight0_3 = "normal"
        this.item_font_weight_roll0_3 = "normal"
        this.item_font_style0_3 = "normal"
        this.item_font_style_roll0_3 = "normal"
        this.item_font_size0_3 = "11px"
        this.item_font_size_roll0_3 = "11px"
        this.item_text_color_roll0_4 = "#5f5f5f"
        this.item_font_family0_4 = "Verdana"
        this.item_font_family_roll0_4 = "Verdana"
        this.item_font_weight0_4 = "normal"
        this.item_font_weight_roll0_4 = "normal"
        this.item_font_style0_4 = "normal"
        this.item_font_style_roll0_4 = "normal"
        this.item_font_size0_4 = "11px"
        this.item_font_size_roll0_4 = "11px"
        this.item_text_color_roll0_5 = "#5f5f5f"
        this.item_font_family0_5 = "Verdana"
        this.item_font_family_roll0_5 = "Verdana"
        this.item_font_weight0_5 = "normal"
        this.item_font_weight_roll0_5 = "normal"
        this.item_font_style0_5 = "normal"
        this.item_font_style_roll0_5 = "normal"
        this.item_font_size0_5 = "11px"
        this.item_font_size_roll0_5 = "11px"
        this.item_text_color_roll0_6 = "#5f5f5f"
        this.item_font_family0_6 = "Verdana"
        this.item_font_family_roll0_6 = "Verdana"
        this.item_font_weight0_6 = "normal"
        this.item_font_weight_roll0_6 = "normal"
        this.item_font_style0_6 = "normal"
        this.item_font_style_roll0_6 = "normal"
        this.item_font_size0_6 = "11px"
        this.item_font_size_roll0_6 = "11px"
        this.item_text_color_roll0_7 = "#5f5f5f"
        this.item_font_family0_7 = "Verdana"
        this.item_font_family_roll0_7 = "Verdana"
        this.item_font_weight0_7 = "normal"
        this.item_font_weight_roll0_7 = "normal"
        this.item_font_style0_7 = "normal"
        this.item_font_style_roll0_7 = "normal"
        this.item_font_size0_7 = "11px"
        this.item_font_size_roll0_7 = "11px"
        this.item_text_color_roll0_8 = "#5f5f5f"
        this.item_font_family0_8 = "Verdana"
        this.item_font_family_roll0_8 = "Verdana"
        this.item_font_weight0_8 = "normal"
        this.item_font_weight_roll0_8 = "normal"
        this.item_font_style0_8 = "normal"
        this.item_font_style_roll0_8 = "normal"
        this.item_font_size0_8 = "11px"
        this.item_font_size_roll0_8 = "11px"
 
You cannot use variables in the way you desire.

You can, however, use the eval statement as so:

eval("this.item_text_color_roll0_" + count) = "#5f5f5f";

eval is not usually a recommended function, however. If "this" is an object you created, then you might consider a multi-dimensional array (looks like 9x8?) to hold the properties of "this" and set them, looping over the indeces.

'hope this gets you started...

Dave


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
O Time, Strength, Cash, and Patience! [infinity]
 
...or you can do what Dan said! :)


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
O Time, Strength, Cash, and Patience! [infinity]
 
I tried this and it does not work.
Code:
	for (count=0; count <9; count ++) {
			eval("this.item_text_color_roll0_" + count) =  "#5f5f5f"
			eval("this.item_font_family0_" + count) = "Verdana"
       		eval("this.item_font_family_roll0_" + count) = "Verdana"
        	eval("this.item_font_weight0_" + count) = "normal"
        	eval("this.item_font_weight_roll0_" + count) = "normal"
        	eval("this.item_font_style0_" + count) = "normal"
        	eval("this.item_font_style_roll0_" + count) = "normal"
        	eval("this.item_font_size0_" + count) = "11px"
        	eval("this.item_font_size_roll0_" + count) = "11px"
		}
 
That's what I get for not testing before I post a response. Sorry about that!

Better to try Dan's solution.

Dave


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
O Time, Strength, Cash, and Patience! [infinity]
 
Much as this is the JavaScript forum, I'm inclined to believe that what you're trying to achieve could probably be done simpler with plain old CSS.

If you could explain what goal you're trying to achieve, there may be a simpler way.

---
Marcus
better questions get better answers - faq581-3339
accessible web design - zioncore.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top