PDA

View Full Version : Javascript error


mgx-alander
10-10-2009, 07:54 PM
Ok

I got this issue

I got this variable already defined say XCon4

XCon4 = new GIcon() (XCon ranges from 1 to 8)

after alot of processing, the server generates this array of ions (There are a total of 8ions type)

ion stores this variable name

ion[0] = "XCon4"
ion[1] = "XCon3"

i got another function that requires a type GIcon, however this variable name is stored in
ion[0], how do i convert ion[0](of type string) to XCon4 (of type GIcon)???


This is not a Pure JS Function, it integrates asp.net with js)

There is a need to convert,

thanks in advance

violentk
11-10-2009, 03:09 AM
XCon4 = new GIcon();
ion[0] = 'XCon4';
eval( " DoFunction (" + ion[0] + ")" );

violentk
11-10-2009, 03:27 AM
eval sucks in performance and security...

var XCon4 = new GIcon();
var ion[0] = 'XCon4';
DoFunction (window[ion[0]]);


or


var XCon4 = new GIcon();
var ion[0] = 'XCon4';
var tempfunction = new Function ( " DoFunction (" + ion[0] + ")" );
temfunction();

mgx-alander
11-10-2009, 03:42 AM
Thank you for the help violentk

But I managed to solve this issue using my server side programming, it was an overhaul of my previous code :s27:

but thx god it works

violentk
11-10-2009, 03:44 AM
Thank you for the help violentk

But I managed to solve this issue using my server side programming, it was an overhaul of my previous code :s27:

but thx god it works

np =p
ya i bet u store it as arrray of GIcon() :)

mgx-alander
11-10-2009, 03:58 AM
wtf its 4am? :eek:

i didnt know i code for so long liao :eek: