I want to pass array[x] to a variable so that I can use the variable in .innerHTML. I've researched and not found a reference.
Any help appreciated. Big thanks.
I want to pass array[x] to a variable so that I can use the variable in .innerHTML. I've researched and not found a reference.
Any help appreciated. Big thanks.
Do you mean how can you pass it in a function?
Code:(function(value){ document.getElementByid('element').innerHTML = value; }(array[x]));
Jeremy | jfein.net
ok, let me show you my function that doesn't work:
can we start here?Code:function captionToDiv() { document.getElementById("captionHere").innerHTML = "captionsList[caption]"; return false; }
Should work, aslong as you make sure captionsList is defined before you call captionToDiv(). If you want to pass it as a parameter:Code:function captionToDiv() { document.getElementById("captionHere").innerHTML =captionsList[caption]; return false; }
Code:function captionToDiv(val) { document.getElementById("captionHere").innerHTML =val; return false; } captionToDiv(captionsList[caption]);
Jeremy | jfein.net
The function to create and fill the array runs before I call captionToDiv().
Did you mean for me to use the code you have highlighted?
here is the computed code which returns error: missing ) after formal parameters. Pointing to line 1.
I don't see where ")" is needed.Code:function captionToDiv(captionsList[caption]) { document.getElementById("captionHere").innerHTML = "captionsList[caption]"; return false; }
No - change your code to:
Code:function captionToDiv() { document.getElementById("captionHere").innerHTML = captionsList[caption]; return false; }
Jeremy | jfein.net
receiving error: captionsList not defined. It is defined in the <head> and also in the function that creates the array, and also here:
am I missing something?Code:function captionToDiv() { var captionsList; document.getElementById("captionHere").innerHTML = captionsList[caption]; return false; }
Bookmarks