Urgent: Get return variable

Hi!
I have a trouble on getting variables.
I have a javascript function like:
function getWidth()
{
width = ....
return width
}

I need to get that return value from an asp page, something like:
Response.Write("SCRIPT LANGUAGE='JavaScript'>")
Response.Write("getWidth()")
Response.Write("</SCRIPT>")

But, how can I get this value? How can I do it??

Thanks so much
mbarriocAsked:
Who is Participating?
 
prohacxConnect With a Mentor Commented:
Hi there again!

Yes, Sybe is right about that: I can think of ways (response.write) to build Client side functions dynamically (or to fill client side vars dynamically) on the server, but you cannot set a server side variable from the client without going to the server, that means: GET or POST something.

So, the only way to do something you want to do is get the value client side like you have to and GET (e.g. use a link) or POST (e.g. a form) (although you can GET a form too ;-) it to the server where you can use it to build the page that will then display the IFRAME where you want it.

So here's an example:

PAGE1.ASP
=========

<%@ Language=VBScript %>
<%Response.Expires = 0%>
<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">

<script language="JavaScript1.2">

function passIt() {

     document.location = "page2.asp?width=" + event.screenX;

}

</script>

</HEAD>
<BODY onLoad="javascript: passIt();">

<P>Going to page 2...</P>

</BODY>
</HTML>


PAGE2.ASP
=========

<%@ Language=VBScript %>
<%Response.Expires = 0%>
<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
</HEAD>
<BODY>

<P>You passed offset = <%=Request.QueryString("width")%></P>

</BODY>
</HTML>


That's the only way to do it in ASP!


0
 
sybeCommented:
Response.Write("SCRIPT LANGUAGE='JavaScript'>")
// don't use quotes in the reponse.write:
Response.Write(getWidth())
Response.Write("</SCRIPT>")

0
 
Wouter BoevinkMasterCommented:
You want to get te results from a client side function (the javascript part) at the server (the asp part)?
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
prohacxCommented:
Sybe,

you cannot call a JS function from within ASP, so I don't think this will work.

MBarrioc, can you please explain your problem a little more, what do you want to do? Do you want to display the return value of a Javascript function in an page using ASP? Because it's like I said, you cannot call JS in an ASP page.

You can use Javascript to write something to the screen though:

<script language="Javascript1.2">
  document.write "\n " + getWidth();
</script>

Or use an alert or so to display the width...
0
 
sybeCommented:
prohacx,

yes, you are right. Of course I know that. But I did not realize that the javascript function called was a client side function. Javascript can be used on the server all the way. But if the getWidth() function is on the client, then of course there is no way to call it from the server.


mbarrioc,

Please don't mix client-side and server-side functions. There is *no way* you can call a client-side function from the server. It's a very common mistake, and one of the first things you should learn: client-side code (javascript in the browser) runs on a totally different computer then server-side code (asp on the server).

0
 
mbarriocAuthor Commented:
prohacx,

you are right, I think that I'm mixing those functions, but all I want is to retrieve a value into a variable, and that value I can only calculate into a javascript function.

I can call that function an display the result to the screen, but I need the value returned to build an iframe specifying that width value, and I think that this value must be in a variable.
0
 
GaryCommented:
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

Accept Answer by prohacx

Please leave any comments here within the next seven days.
 
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
 
GaryC123
EE Cleanup Volunteer
0
All Courses

From novice to tech pro — start learning today.