?
Solved

Urgent: Get return variable

Posted on 2003-03-24
7
Medium Priority
?
214 Views
Last Modified: 2008-03-10
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
0
Comment
Question by:mbarrioc
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 28

Expert Comment

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

0
 
LVL 12

Expert Comment

by:Wouter Boevink
ID: 8194670
You want to get te results from a client side function (the javascript part) at the server (the asp part)?
0
 
LVL 5

Expert Comment

by:prohacx
ID: 8194713
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 28

Expert Comment

by:sybe
ID: 8194739
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
 

Author Comment

by:mbarrioc
ID: 8195669
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
 
LVL 5

Accepted Solution

by:
prohacx earned 300 total points
ID: 8196085
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
 
LVL 58

Expert Comment

by:Gary
ID: 9313127
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

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question