Sytse said:
See code below.
Why does my browser complain that test is not defined, while the alert
call is valid?
It does not matter in which order I define create and test.
It seems to be a scope issue, but how can this be solved?
function create() {
document.write ("<A href=\"#\" onClick=\"test();\">test</A>
<BR />");
document.write ("<A href=\"#\"
onClick=\"alert('alert');\">alert</A>");
<BODY onLoad="create()">
You can't use document.write *after* the onLoad event has been
triggered. The document.write call is used to add stuff to a page that's
currently being built. The onload event is triggered after it's finished
building (it's already built). So making a call to document.write after
that, will make the browser start a brand new page with that new HTML
that you're document.writing. If you were to view-source, you'd see only
the second of the first of those two document.write HTML strings
present. It would never have reached the second one because the first
one started a new page.