You can't explicitly call the javascript function from the ASP page. The ASP page is executing on the server and therefore it is not processing client-side code(like javascript), only the server-side portion. When it is finished it finishes sending the page to the client (browser) and exits, cleaning up after itself and deallocating the memory that was in use. At this point the client browser has just finished displaying the page and started registering events and parsing the scripts embedded in it (client-side scripts like javascript in script tags). At this point the client-side javascript can execute, but since the server-side script no longer exists they cannot interact. There is also the small problem that they were executing on two seperate machines that don't really every connect during the process.
Executing the code during a page event is really the only way you can execute javascript code on a web page. It is possible to fake calling javascript from the server, but that is all.
For example, you can write javascript commands straight into the script tags without putting them in a function. These commands will fire as the browser starts to process the page. If you turn the Response.Buffer off so that the server sends the html to the client as soon as it processes parts of the script rather than weaiting until it has processed each one, than you can output javascript to the browser that will run before the page has fully loaded.
Here is an example of a loading page I made at some point to show this principle:
Code:
<%
Response.Buffer = False
%>
<html>
<head>
<script language="JavaScript">
<!--
document.writeln("Script block 1 is done");
//-->
</script>
<%
'Some dummy code that is pretending to do a lot of server-side calculations
Dim TESTLOADTIME
TESTLOADTIME = 2
Dim testTime, testChk
'just a loop to slow the loading
testTime = Now()
testChk = second(Now()) + TESTLOADTIME
Do Until second(testTime) >= testChk
testTime = Now()
Loop
%>
</head>
<body onLoad="alert('The page has finished loading now.');">
</body>
</html>
Now there isn't much javascript executing before the server has finished processing, but it should be enough to show the concept.
-Tarwn ________________________________________________
Get better results for your questions: faq333-2924
Frequently Asked ASP Questions: faq333-3048