Wrox Programmer Forums
|
Classic ASP Basics For beginner programmers starting with "classic" ASP 3, pre-".NET." NOT for ASP.NET 1.0, 1.1, or 2.0
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 31st, 2005, 03:36 PM
Friend of Wrox
 
Join Date: Jan 2005
Posts: 108
Thanks: 0
Thanked 0 Times in 0 Posts
Default How to pass javascript variable to server side

Hi, all,

I have a function defined in the server side(<%...%>) in asp, now I want to call the function from javascript and pass the javascript variable as argument to the server side function, is it possible??
For example:
<%
 function resizeImage(fileName, width, height)
    ............
 end function
%>
<script langage=javascript>
  var fileName = "......."

  answer = "<%=resizeImage(fileName , 200,200)%>"
</script>
The function must be defined in the server side. I know the above line doesn't know the variable "fileName", is there any way I can pass it to the function in the same page????? don't think about call the page itself again or submit the form, just in the same page.

andraw


 
Old April 1st, 2005, 12:28 AM
Friend of Wrox
 
Join Date: May 2004
Posts: 642
Thanks: 0
Thanked 43 Times in 42 Posts
Default

Hi,

 You cannot call server side functions from javascript, You can submit the form and then call the function.

Om Prakash
 
Old April 1st, 2005, 10:27 AM
Friend of Wrox
 
Join Date: Jan 2005
Posts: 108
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks!

Andraw

 
Old March 7th, 2006, 12:50 AM
Registered User
 
Join Date: Mar 2006
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,

Though it is not possible but, another solution is perfect to call server-side function that is

In this problem [u]you cannot pass a variable to server side function </u>but, you can pass variable value to that function and it will send result back to client on same page.

DOIT.

--Anoop K Goyal
    Jaipur


 
Old April 26th, 2006, 06:05 AM
Registered User
 
Join Date: Mar 2006
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I want to access javascript variable in vbscript.
It can be done if javascript code is runat=server but,
if [u]I want to run this on client-side then how it will be</u>? write me.


 
Old April 26th, 2006, 06:08 AM
Registered User
 
Join Date: Mar 2006
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I want to get FILE input box value in vbscript variable for validation purpose at client side.

How can I do it?

 
Old April 26th, 2006, 08:07 PM
Friend of Wrox
 
Join Date: Jan 2004
Posts: 1,870
Thanks: 12
Thanked 20 Times in 20 Posts
Send a message via AIM to mat41
Default

;;;I want to access javascript variable in vbscript. It can be done if javascript code is runat=server but.

How do you do this I am intrigued?

Wind is your friend
Matt
 
Old May 2nd, 2006, 09:06 AM
Friend of Wrox
 
Join Date: May 2006
Posts: 643
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Ahhh... this response is to the original post. It looks to me that you might want to use Ajax.
I am sure you would have thought of that yourself if you had been exposed to it before now.

Essentially, Ajax allows you to call server-side functionality from within javascript.

There is lots of info on Ajax and how to do it so all you have to do is a Google search to start exploring.

Woody Z http://www.learntoprogramnow.com
 
Old May 8th, 2006, 06:28 PM
Friend of Wrox
 
Join Date: May 2006
Posts: 643
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by mat41
 ;;;I want to access javascript variable in vbscript. It can be done if javascript code is runat=server but.

How do you do this I am intrigued?
I am not sure I am addressing your question... but have a look at this - It is all server side, of course.

Code:
<%@LANGUAGE="VbScript"%>

<SCRIPT LANGUAGE="JavaScript" RUNAT="Server">

var m = "I am in a JavaScript Variable"

function HelloJavaScript()
   {
      return "Hello World in JavaScript";
   }

function printWords(words)
   {
      return "These words were passed in to a JavaScript function \"" + words + "\""
   }

</SCRIPT>

<SCRIPT LANGUAGE="VBScript" RUNAT="Server">

function HelloVbScript
   HelloVbScript="Hello World in VBScript"
end function

function passingValueToVbscriptFromJavascript(myValue)
   passingValueToVbscriptFromJavascript = "We passed the words: """ &  myValue & """ From JavaScript to VbScript"
end Function

</SCRIPT>

<%

' we are back in VbScript here...
Response.Write(HelloVbScript() + "<br/>")
Response.Write(HelloJavaScript() + "<br/>")

' we are calling Javascript from within VbScript
Response.Write(printWords( HelloVbScript ) + "<br/>")

' and here is a javascript variable being accessed from vbscript
Response.Write m

%>
Woody Z http://www.learntoprogramnow.com
 
Old May 8th, 2006, 06:53 PM
Friend of Wrox
 
Join Date: Jan 2004
Posts: 1,870
Thanks: 12
Thanked 20 Times in 20 Posts
Send a message via AIM to mat41
Default

Very interesting indeed, thankyou for the in-site. After looking at your code I done some further looking pureley out of interest (I can not imagine why I would have a need for it however find it interesting) This link would add to the usefulness of this post:

http://www.webhostingtalk.com/archiv...d/91704-1.html

Wind is your friend
Matt





Similar Threads
Thread Thread Starter Forum Replies Last Post
how to pass javascript variable to xsl eruditionist XSLT 4 September 8th, 2008 08:37 AM
javascript after server side code k.manisha ASP.NET 1.0 and 1.1 Professional 1 March 12th, 2007 06:28 PM
How To Pass Javascript variable to vbscript pbcatan Classic ASP Databases 1 December 18th, 2006 08:42 AM
Pass variable to linked server query sofya SQL Server 2000 4 November 23rd, 2004 02:38 PM
sharing a server-side variable with client-side pigtail Javascript How-To 6 November 4th, 2004 02:01 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.