PDA

View Full Version : Calling a Javascript function.


flash
12-04-2002, 11:02 AM
Hello.

I have a function set in Javascript:



<script language="JavaScript">

function Display()
{

str = "beans on toast";
document.all['previewDisplay'].innerText = str;

}
</script>



Is it possible for me to call this function with ASP using Response.Write or something like that?

Any help would be great!!! :thumbsup:

Thanks.

Flash

Morgoth
12-04-2002, 02:30 PM
Hum, if:
Call Display()
Doesn't work, then I think you might not be able to, on the same page.

All HTML and scripts in HTML like javascript are executed after ASP, I think.

whammy will know, he knows alot about javascript and this type of situation.

Maybe what you could do, is only put the function calling for java script in with an If statement (This might work for what you need).

Not:
If 0 = 0 Then
Call Display()
End If

This:
If 0 = 0 Then
%>
{
Javascript calling script and Display()
}
<%
End If

See what I mean?

Or if all this doesn't work, then you could always tell us what your trying to do, and maybe ASP has a method.
:cool:

Roelf
12-04-2002, 03:20 PM
the function you posted is a client side function. in asp, it is not possible to execute the function while executing the serverside code in the asp file. The serverside code is executed, this produces clientside code which is sent to the client. The client side code is executed when the page arrives in the browser, or triggered in the browser by an eventhandler.
asp.net provides functionality the other way around, you can execute serverside code while the page is still in the browser, f.e. a serverside eventhandler, for a clientside event
what you can do is response.write the function call to the page

like
Response.write("<scr\ipt>Display()</scr\ipt>")

but that will insert a call to the function which is executed when the page is in the browser

Enough??

flash
12-04-2002, 04:09 PM
Thanks :D :thumbsup:

I found another way around my problem now...:p

Morgoth
12-04-2002, 07:58 PM
Originally posted by Roelf
the function you posted is a client side function. in asp, it is not possible to execute the function while executing the serverside code in the asp file. The serverside code is executed, this produces clientside code which is sent to the client. The client side code is executed when the page arrives in the browser, or triggered in the browser by an eventhandler.
asp.net provides functionality the other way around, you can execute serverside code while the page is still in the browser, f.e. a serverside eventhandler, for a clientside event
what you can do is response.write the function call to the page

like
Response.write("<scr\ipt>Display()</scr\ipt>")

but that will insert a call to the function which is executed when the page is in the browser

Enough??


I already said that.