Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript How-To
|
Javascript How-To Ask your "How do I do this with Javascript?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript How-To 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 April 13th, 2008, 08:09 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 141
Thanks: 1
Thanked 0 Times in 0 Posts
Default How to assign a new value to Classic ASP variable

Hello,

How to assign a new value to Classic ASP variable in Javascript?

Example:
<%
dim strAction
strAction = "1"
%>

<script language="JavaScript">
  // How can assign value "2" to strAction?
</script>

<% response.write "strAction: " & strAction %>
Thank you. :)

MCinar

Love all the creatures because of the creator.
__________________
MCinar

Love all the creatures because of the creator.
 
Old April 14th, 2008, 12:05 AM
Friend of Wrox
 
Join Date: May 2004
Posts: 642
Thanks: 0
Thanked 43 Times in 42 Posts
Default

Example:
<%
dim strAction
strAction = "1"
%>

<script language="JavaScript">
 var s = <%=strAction%>
 alert(s);
</script>


Om Prakash
 
Old April 14th, 2008, 08:30 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 141
Thanks: 1
Thanked 0 Times in 0 Posts
Default

Thanks for the reply.
I meant it
Example:
<%
dim strAction
strAction = "1"
%>

<script language="JavaScript">
 <%strAction%> = 2 // if this is possible.
 alert(s);
</script>


MCinar

Love all the creatures because of the creator.
 
Old April 14th, 2008, 08:37 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

All your code will do is create some client-side code that reads:
Code:
1 = 2;
alert(s);
Obviously you can't set one equal to two and neither is 's' defined.

You must get it clear in your mind where the code runs. The ASP runs on the server after the .asp file is loaded in response to a request received by IIS and passed to the ASP handler. It is then sent to the client where the JavaScript runs. The two systems cannot directly interact.

--

Joe (Microsoft MVP - XML)
 
Old April 14th, 2008, 06:02 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

IME the oly effective way I have found is to post the JS value (hidden form variable or otherwise) to another page to get it into ASP. Yes this requires another page however it does not have to have a user interface EG post > get value > redirect

There are loads of example of this on the www. Ask Google you will be suprised at how many pages detail exactly how to do this.

That example om_prakash has given you passes the variable the other way, clearly very easy to do this. BTW - As Joe says, you can not use ASP like you have in your second post

Wind is your friend
Matt
www.elitemarquees.com.au





Similar Threads
Thread Thread Starter Forum Replies Last Post
session variable lost after redirec in classic ASP beetle_jaipur Classic ASP Professional 8 November 21st, 2008 02:18 AM
assign XSLT variable to a wml variable arunagottimukkala XSLT 2 October 19th, 2007 05:15 AM
assign javascript variable to asp variable manjunath_c_k Classic ASP Basics 1 September 14th, 2006 07:35 AM
assign a recordset to a variable biggen55 VB How-To 1 March 26th, 2004 02:26 PM





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