?
Solved

How to assign JavaScript variable to ASP variable

Posted on 2003-02-20
10
Medium Priority
?
299 Views
Last Modified: 2012-06-27
Hi,
 
I need to assign JavaScript variable value of 'sNewName' to ASP variable 'vNames'

Could any one help me on this please...

Thanks,
Chandi


test.asp

<%
Dim vNames
...

%>

<SCRIPT>

var sNewName="Jones";              
           

function update() {

<%
  vNames = sNewName
%>

}

</SCRIPT>
0
Comment
Question by:chandima
[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
10 Comments
 

Expert Comment

by:kennethwkc
ID: 7991366
javascript is a client script and asp is a server side
and i dun think you can assign the value of the JS variable to asp variable in runtime.

If post back solution is acceptable
i would suggest u to store ur javascript variable into a html hidden field, post back, then retrieve that variable
using request.form then assign it back to ur asp variable

If this is not acceptable, please give me more of ur requirements and i will try to help

Kenneth
0
 
LVL 3

Expert Comment

by:AmericanDogma
ID: 7991420
You can not assign a Javascip variable to an ASp variable however you can assign an asp variable to a javascript variable.

AD
0
 
LVL 4

Accepted Solution

by:
Wakie earned 400 total points
ID: 7991466
Hi chandima,

Your best option would be to do this:

<SCRIPT>

var sNewName="Jones";              
         

function update() {

location = "test.asp?vNames=" + sNewName;

}

</SCRIPT>

You would then fetch this query string in your test.asp script:

vNames = Request.QueryString("vNames")

Regards,
Wakie.
0
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!

 
LVL 7

Expert Comment

by:ASPSQLServerCOM
ID: 7991516
hi,
can u tell us wht is functionality u want to do bcs as  javascript is client side scripting and asp script which is VB script is server side script so u have to post back u r form for tht, but if u r having lot value already entered in the form and u wan t such thing then use remote scripting, if u want to know more on remote scripting then tell me

Dipesh
0
 
LVL 10

Expert Comment

by:apollois
ID: 7991595
Hi chandima,

If you are submitting a form, one common way to do this is by setting the value of a hidden form field to the javascript variable.  If you don't need a form, then Wakie has the best answer for you.

=================================================
<%
Dim vNames
...


'--- Get Value from either QueryString or Form element ---
  vNames = Request("vNames")    

IF Len(vNames) > 0 THEN
     '--- ADD YOUR CODE TO PROCESS vNames HERE ---
END IF
     
%>

<HTML>
<HEAD>
<SCRIPT LANGUAGE="JAVASCRIPT">

var sNewName="Jones";              
           
function update(poFormElem) {
     poFormElem.value = sNewName;
     return true;
}

</SCRIPT>
</HEAD>
<BODY>

<FORM name="MyForm" onSubmit="update(this.vNames);">
<INPUT name="vNames" type="hidden" value="">
<!--- ADD YOUR OTHER FORM ELEMENTS HERE --->
</FORM>
</BODY>
</HTML>
============================================================

Best Regards,
apollois
0
 

Expert Comment

by:dirtyfoot
ID: 7992111
Hello,

If you don't wanted to post back, you may try to use cookies as a temp. space.

1. Store the value into the cookies by JavaScript.
2. Read the Cookies from the ASP.


e.g.
==================================================
1.
<SCRIPT LANGUAGE="JavaScript">
     function setCookie(name, value, days) {
          var dc = document.cookie;
          if (!days) days = 1; // default to 1 day if empty

          var expdate = new Date();
          expdate.setTime(expdate.getTime() + days*24*60*60*1000);

          dc = name + "=" + escape(value) +
          "; expires=" + expdate.toGMTString();
     }
</SCRIPT>



<FORM>
     <INPUT TYPE=button VALUE="Set A Cookie" onClick="setCookie('my_cookie','it is crunchy', 30)">
</FORM>


======================================================
2.

<%= Request.Cookies("my_cookie") %>
0
 
LVL 4

Expert Comment

by:Wakie
ID: 8001990
chandima,

Many good solutions have been proposed. Please select the solution that best answers your question.

Regards,
Wakie.
0
 
LVL 10

Expert Comment

by:apollois
ID: 8125623
Hi chandima,

Your question is in danger of being classified as "abandoned".  Please take action in a timely manner to close this question.

     -- Days since last post:                    18
     -- Days since the question was opened:          20
     -- Last post you made:                    02/20/2003

If you used an answer proposed by one of the experts, please select his/her comments as an answer.  

If you solved the problem yourself, please so state, post your solution, and post a zero-point question with Community Support (http://www.experts-exchange.com/Community_Support/).  Include a link to this question and a request to refund your points.

If no one answered you question or helped you arrive at an answer, then you can request a refund by posting a zero-point question with Community Support.

DO NOT ACCEPT THIS COMMENT AS ANSWER.

Best Regards,
>apollois<
0
 
LVL 10

Expert Comment

by:apollois
ID: 8208494
========================================
ABANDONED QUESTION FINAL NOTICE
========================================

It appears that this question has been abandoned:
     -- Days since the question was opened:          33
     -- Last post of the question asker:          02/20/2003

I will make a final recommendation to the EE Moderators on its resolution in one week. I appreciate any comments that would help me to make a recommendation.  If you disagree with my initial recommendation, I urge you to post a comment.

In the absence of responses, I will make the below recommentation.

RECOMMENDATION:
     [ACCEPT wakie COMMENT 02/20/2003 07:42PM PST AS ANSWER]

Silence = You agree with recommendation or don't care.

DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

>apollois<
EE Cleanup Volunteer
~~~~~~~~~~~~~~~~~~~~~~~~
chandima, if you feel that your question was not properly addressed, or that none of the comments received were appropriate answers, you may post a request in Community support (with a link to this page) to refund your points. http://www.experts-exchange.com/Community_Support/
0
 

Expert Comment

by:SpideyMod
ID: 8358889
per recommendation

SpideyMod
Community Support Moderator @Experts Exchange
0

Featured Post

Technology Partners: 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 would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

743 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