Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I call a function with asp cod?

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
I have a function inside the script tag of a html page. How do I call that function using ASP code written in JScript? (I want to call it from within the asp code block.) Have tried with return and function, but I only get an error message ('return' statement outside of function). Suggestions, anybody?
 
Let me try to understand, you want to call a client side function (eg in
Code:
<Script>...</Script>
tags) within a server side script (eg in
Code:
<%...%>
tags). If it's that, you won't be able to do it 'cause the two scripts doesn't run on the same machine.
You have two solutions :
- copy your function in asp in order to access it on the server.
- let your client function do the job by passing it the info you want like this :
Code:
<Body onload=&quot;myClientFunction(<%=myServerVariable%>);&quot;>
Water is not bad as soon as it stays out human body ;-)
 
Ok, how do I get a function, that is now executed by an onClick of a button, to execute automatically when placed in an if/else?
 
I don't understand the question [sad] Water is not bad as soon as it stays out human body ;-)
 
It's a bit fuzzy, I know. As it is now: When you click on a button (html) a script is called (<script>...</script>).
What I want: I want to skip the extra click and execute the script if my counter is > 2.
 
Let me see if I understand. You don't want your function to be called by a button anymore but by a test on a variable value? If it's that, tell me if this counter is on client side or in server side. Water is not bad as soon as it stays out human body ;-)
 
So do like that :
-between your asp (
Code:
<%...%>
) tags write this :
Code:
<%
..
dim doTheJob  'boolean
doTheJob = (myCounter > 2)
..
%>
beware that the declaration of the boolean variable &quot;doTheJob&quot; has a page scope (eg : not in a sub or function)

in your htmlCode (assuming the name of the function you want to call is &quot;myFunction&quot; :
Code:
<Script>
function testCounter() {
   if (<%=doTheJob%>)
      myFunction();
}
...
.
</Script>

<Body onload=&quot;testCounter();&quot;>

beware that the
Code:
<%=..%>
asp primitive may return the string value of the boolean so maybe the test will be
Code:
if (<%=doTheJob%>==&quot;true&quot;)[code] or something like that. Use the &quot;View source&quot; of your web browser to determine the good test.
 Water is not bad as soon as it stays out human body ;-)
 
The problem here is that when the user is looking at the page, your server-side counter no longer exists. Server-side code only exists to process a script and send the results to a user. Then it is done and over and starts releasing the memory it was using. This is all done before the page is available for the user to interact with, so your looking at a one way road. You can write as much data to the response buffer as you want, but it does not come back upstream from the client to execute or access the ASP script (except when submitted to a new page). If the counter is something that occurs only once per page (instead of a loop inside the script) or is a total, or any type of value like that, you could response.write a javscript variable inside your script tags so that your code could access it later. If you are trying to cause an action on the clients machine while your looping on the server, you can't, because if the ASP script is still processing, the client doesn't have a page yet and if the client has a page then the ASP script is no longer processing.
-Tarwn The three most dangerous things in the world are a programmer with a soldering iron, a hardware type with a program patch, and a user with an idea
-computer saying (Wiz Biz - Rick Cook)
 
Thank you guys for you help! I will try this first thing monday morning.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top