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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Javascript Object and eval() help needed

Status
Not open for further replies.

simonchristieis

Programmer
Jan 10, 2002
1,144
GB
I have an object

function a(b,c,d){
a.name=b
a.age=c
a.dob=d
}

Billy = new a("Billy",26,"23/05/1977")

no problems so far

now i want to create a loop that will access whichever properties i need using this array


propArray = new Array("name","age","dob")



function write(){

name = "Billy"

i=1;
while i < 3 {

temp = &quot;formfield&quot;+i

// this is where the problem lies

temp = eval(name.propArray)

// i cannot get this eval function call to work

}

}


any ideas i would be very grateful

please excuse the sloppy code - this is not the actual code - just made it up to clarify things

 
Try this....

Code:
temp = eval(name + &quot;.&quot; + propArray[i])

Programming today is a race between software engineers striving to build better and bigger idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. - Rick Cook
 
Hey - reading your code reminded me that I should be working on more Object Oriented coding - looks pretty neat.

Programming today is a race between software engineers striving to build better and bigger idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. - Rick Cook
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top