On Nov 18, 4:00 pm, Jean wrote:
Quote:
function myFunction(){
document.write('var path="../images/2008/');}
>
I use this kind of function to declare the variable path.
It's on a extern javascript file. If I use this function
in an other function to define var path, the result is an
error: path not defined. Can someone explain to me why
this doesn't work?
|
Apart from being quite an odd thing to want to do, and probably
considerably more simply (and reliably) achieved by other means), -
document.write - inserts HTML contents into the HTML stream (assuming
the document is not already closed at the time) and in that context
your 'var path="../images/2008/' is just text content (not script
source code (to be the latter it would have to appear in a SCRIPT
element)), and even if that text were interpreted as script content it
would only result in a syntax error as the opening double quote at the
beginning of that appears to have been intended to be a string literal
is not matched with a closing double quote.