Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
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 June 13th, 2005, 11:34 PM
Registered User
Points: 1,897, Level: 17
Points: 1,897, Level: 17 Points: 1,897, Level: 17 Points: 1,897, Level: 17
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2005
Location: Mumbai, Maharastra, India.
Posts: 352
Thanks: 14
Thanked 0 Times in 0 Posts
Send a message via Yahoo to rupen
Default storing Javascript variable to ASP variable

Hi,
There is a javascript funcion, in which I am writing some ASP code, now in that ASP code there is one variable to which I want to assign javascript variable, Can anyone tell me how to do that. See below:
-----------------
function setAct1(src,trg)
{ var tmp
    var x=document.getElementById(trg)
    var y=document.getElementById(src)
    var str
    tmp = y.options[y.selectedIndex].value
    str = "select * from ActivityMaster where wtid = " + tmp + ",objConn"
    <%dim strSQL %>

'' Error I receive is "Type mismatch for following line."

    <%strSQL %> = str
    <%objRSAct.open strSQL%>
    <%objRSAct.MoveFirst%>
    <%do while not objRSAct.EOF%>
    var elOptNew = document.createElement('option')
    elOptNew.value = <%=objRSAct.fields("actid")%>
    elOptNew.text = "<%=objRSAct.fields(1)%>"
    x.add (elOptNew)
    <%objRSAct.MoveNext%>
    <%loop%>
}
</script>
------------
Thankx in advance.:)

 
Old June 14th, 2005, 04:18 AM
Friend of Wrox
Points: 686, Level: 9
Points: 686, Level: 9 Points: 686, Level: 9 Points: 686, Level: 9
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2005
Location: Kolkata, West Bengal, India.
Posts: 128
Thanks: 0
Thanked 0 Times in 0 Posts
Default

You have to write the Sql query in ASP separately, assign an ASP variable to trap the result value. Then in the javascript function define a variable to assign the ASP variable value like:

var a=<%=someASpvalue%>

remember to write ASP select statement before the javascript function executes.
I think this might work.
 
Old June 14th, 2005, 05:25 AM
Registered User
Points: 1,897, Level: 17
Points: 1,897, Level: 17 Points: 1,897, Level: 17 Points: 1,897, Level: 17
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2005
Location: Mumbai, Maharastra, India.
Posts: 352
Thanks: 14
Thanked 0 Times in 0 Posts
Send a message via Yahoo to rupen
Default

Well, I need reverse of it, whatever you said is the case when javascript variable needs value from asp, but here the case is different, I have a query in asp which needs value from javascript variable. Or somply query in ASP needs a parameter which I want to give from javascript.

OR

Can you tell me how to get value of html:<select></select> control in vbscript?
I think then i can get that value in ASP directly, what is ur opinion?



 
Old June 14th, 2005, 05:32 AM
Friend of Wrox
Points: 686, Level: 9
Points: 686, Level: 9 Points: 686, Level: 9 Points: 686, Level: 9
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2005
Location: Kolkata, West Bengal, India.
Posts: 128
Thanks: 0
Thanked 0 Times in 0 Posts
Default

You can get the value of <select> control in ASP using a variable which will be a=request.form(array) here the array is equal to the no. i.e if all the controls in the page are considered to be an array
 
Old June 18th, 2005, 07:40 AM
Registered User
Points: 1,897, Level: 17
Points: 1,897, Level: 17 Points: 1,897, Level: 17 Points: 1,897, Level: 17
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2005
Location: Mumbai, Maharastra, India.
Posts: 352
Thanks: 14
Thanked 0 Times in 0 Posts
Send a message via Yahoo to rupen
Default

That is not working, any solution for my first problem viz. before "OR" i.e.
--------------------
Well, I need reverse of it, whatever you said is the case when javascript variable needs value from asp, but here the case is different, I have a query in asp which needs value from javascript variable. Or somply query in ASP needs a parameter which I want to give from javascript.
--------------------


 
Old April 10th, 2007, 07:06 AM
Registered User
 
Join Date: Apr 2007
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Rupen,
You can assign the javascript variable value to a hidden input type text field and then submit the form for the asp variable to get that hidden input type value..
say your hidden input type name is abc
so ..

in javascript :
where abc is <input type="hidden name="abc" value="" />

<script language=javascript>
document.form.abc.value=wtv value;
document.form.submit();
</script>

in asp:
<% aspvariable=request.form("abc")%>

you know what I mean??
hope it helps..




Similar Threads
Thread Thread Starter Forum Replies Last Post
Accessing ASP variable from Javascript sasidhar79 Classic ASP Basics 2 March 8th, 2017 05:31 PM
assign javascript variable to asp variable manjunath_c_k Classic ASP Basics 1 September 14th, 2006 07:35 AM
set a asp variable with a value in Javascript crmpicco Javascript How-To 6 March 11th, 2005 11:07 AM
set a asp variable with a value in Javascript crmpicco Classic ASP Basics 3 March 10th, 2005 10:46 AM
Javascript variable values into ASP phungleon Classic ASP Basics 2 May 13th, 2004 02:10 PM





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