PDA

View Full Version : Javascript Syntax Query


ionysis
09-19-2001, 06:19 AM
Hello everyone,

The following line of code works fine:

eval("document.getElementById('chingandaNoScript_" + i + "').style.display = \"none\";");


but this next line doesn't work:

eval("document.getElementById('chingandaNoScript_" + i +"').item(nowNext).insertAdjacentHTML(beforeEnd,"dummyChange");");

error message says "char 106" i think - any ideas about the syntax

cheers

Dr. Web
09-19-2001, 11:59 AM
try changing this:

,"dummyChange");");



to this: ,'dummyChange');");

Jon Hanlon
09-19-2001, 07:12 PM
Why on earth would you want to use eval() here?
I see lots of scripts with seemingly random eval() statements thrown in as if eval() was some sort of magical panacea.

eval() is useful for turning a string into an object reference, and also for 'calculator' type operations:

var thing = "images"
var thirdThing = eval("document." + thing + "[2]") // returns a reference to document.images[2]
var myCalc = "3 * 4 + 7"
var result = eval(myCalc) // returns 19

All you need is:

document.getElementById('chingandaNoScript_' + i).item(nowNext).insertAdjacentHTML('beforeEnd','dummyChange')