Click to See Complete Forum and Search --> : using eval()
matt.carter.25
11-03-2004, 03:39 AM
Can anyone help me out,
Im using eval() which works fine in this example
tempObj = eval("document.subGroup.DeleteSG" + CategoryArr[i] + ".checked");
but when i use this
tempObj = eval("document.subGroup." + SubGroupArr[i] + ".value");
i get an error saying ';' expected
Its really doing my head in!!!!
Cheers if anyone has nay ideas
Matt
javaNoobie
11-03-2004, 04:16 AM
We'll have to see more codes.
matt.carter.25
11-03-2004, 04:21 AM
Its ok i found the problem,
One array element was 'No Category'
so i think the Space was causing the problem
Thanks anyway
Matt
Charles
11-03-2004, 05:20 AM
tempObj = eval("document.subGroup.DeleteSG" + CategoryArr[i] + ".checked") is better written as tempObj = document.subGroup.DeleteSG[CategoryArr[i]].checked. The "eval()" function is almost always unnecessary.
matt.carter.25
11-03-2004, 05:37 AM
Not sure what your talking about because that doesnt work!!!
You cant insert a javascript variable in that sort of statement,
Which is why you use the eval() method.
eval() is a very useful method!
matt
senshi
11-03-2004, 06:07 AM
Originally posted by matt.carter.25
Can anyone help me out,
Im using eval() which works fine in this example
tempObj = eval("document.subGroup.DeleteSG" + CategoryArr[i] + ".checked");
but when i use this
tempObj = eval("document.subGroup." + SubGroupArr[i] + ".value");
i get an error saying ';' expected
Its really doing my head in!!!!
Cheers if anyone has nay ideas
Matt
eval(); evaluates a string that is a javascript command....
eval("tempObj = document.subGroup." + SubGroupArr[i] + ".value;");
IS more likely the thing your looking to do, if SubGroupArr[i]==element then the eval would pass the string
tempObj = document.subGroup.element.value;
and work on it as if it was part of your code.
eval(); wont return a value like in functions.
matt.carter.25
11-03-2004, 06:21 AM
Well Sorry to say this but i think you are wrong,
tempObj = eval("document.subGroup.txt" + CategoryArr[i]);
does in fact return a value.
i can now use tempOgj.value!!!!!
plus if you had read all the other replies you would realise that the orginal problem was because i had an element in the array which has a space in it. which is why i had the problem!!!!!
Thanks anyway
Matt
Charles
11-03-2004, 06:26 AM
Originally posted by matt.carter.25
Not sure what your talking about because that doesnt work!!!
You cant insert a javascript variable in that sort of statement,
Which is why you use the eval() method.
eval() is a very useful method!
matt JavaScript has a lot of redundancy in its syntax and all Objects can be referenced as associative arrarys. "eval()" requires the browser to loop back through the parser.
7stud
11-03-2004, 12:55 PM
is better written as:
tempObj = document.subGroup.DeleteSG[CategoryArr[k]].checked.
Not sure what your talking about because that doesnt work!!!
You cant insert a javascript variable in that sort of statement,
Why not? :confused:
In most cases(all?), javascript provides a means to access elements either by their id/name string or by their numeric position in a collection.