It works because the first script references the master javascript where all functions are located. The second script is the actual function you are using on the web page from the master javascript.
In other words, you could have this on a web page:
<head>
<script>
Function 1
Function 2
Function 3
</script>
</head>
While in the body you may have:
<body>
Content
<script>
Function 2
</script>
content
<script>
Function 3
</script>
Content
</body>
A different web page using the same functions might only use Function 1 on the page. You avoid having to duplicate all the functions on every web page by creating an external Javascript master document and reference it on every web page. Then, you only use the functions relevant to the page in question. If you choose to add more javascript code, you only add it to the master javascript and select the correct functions for that page.
Clear as mud?
It doesn’t work because you are attempting to do two things at once.
More specifically, this fails becasue the browser either loads the SRC= file , OR processes the “testfunction()’” code, BUT NOT BOTH. Which is processed is browser dependent, but at least in IE 6, the SRC= overrides and so your testfunction() never gets to be part of the page.
Either way, as you say, put them in separate <script></script> tagged blocks & you’ll be A-OK.