Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Make Javascript varable = asp variable 1

Status
Not open for further replies.

thunderain

Programmer
Jan 10, 2002
40
CA
Hi people

I have an asp variable such as (two examples)

pagelink = "pagelink = objRS (fieldname)

I need to put that variable into a javascript variable such as:

<script language=&quot;Javascript&quot;>

<!--
var urlSend
urlSend = pagelink
//-->

</script>


This example does not work. How do you make a javascript variable equal to an asp variable such as above. I am trying to send the variable in an href. It works if i hardcode the address but i need a variable.


Looked endlessly but cannot find out how.

Thanx
Thunderain
 
try:
<script language=&quot;Javascript&quot;>

<!--
var urlSend
urlSend = <%=pagelink%>
//-->

</script>

[conehead]
 
I tried somthing similar before and tried this again but it doesn't work. You don't seem to be able to use the asp tags inside the javascript

any other ideas?

thanx
thunderain
 
hmmm you should be able to... are you sure the variable is being set properly in the asp?? These should be either VB or JavaScript variables anyway . . . not really asp variables . . . Are you using VB or Javascript in your asp page?

[conehead]
 
Hi,
I built this to test that ability and it works..
(Lousy code techniques but it does show that a JavaScript function can use asp variables - if passed to it in the call ):

testpass.asp:
Code:
<HTML>
<HEAD>
<SCRIPT Language=&quot;JavaScript&quot; >
function ShowMe(var1){
var tst = var1
document.write( &quot;The ASP Variable was &quot; + tst)     }
</SCRIPT>
</HEAD>
<body >
        <FORM NAME=&quot;First&quot; METHOD=&quot;POST&quot; ACTION=&quot;&quot;>
       <%
       dim a
       a = &quot;Test&quot;
       %>
      <Input type=&quot;Button&quot; Name=&quot;Test&quot; Value=&quot;TestMe&quot; OnClick=&quot;ShowMe('<%=a %>')&quot;>
      </FORM>
      
</body>
</html>


It appears that it must get it this way, since just assigning it within the function does not work..
[profile]

 
I am using VB Script ( <% @Language=&quot;VBScript&quot; %> )
When i do it hardcoded like this it works perfect with the new window opening up with heinz page, with my href shown below:

<script language=&quot;Javascript&quot;>
<!--
var urlSend
urlSend = &quot;//-->
</script>


<a href=&quot;brandserv-list.asp&quot; onclick=&quot;window.open(urlSend,'','toolbar=0,location=0,directories=0,width=400,height=400');&quot;>window opener</a>

But when i put asp line:

<% pagelink = &quot; %>

And replace urlSend = line with:

urlSend = <%=pagelink%>

then the new window does not open

Thanx
thunerain
 
Hi,
Try placing the JavaScript inside a function and pass it the href info...

So maybe:

Code:
[HEAD]
<script language=&quot;Javascript&quot;>
<!--
function GoThere(addr){
var dest = addr
var urlSend
urlSend = addr
window.open (urlSend,'','toolbar=0,location=0,directories=0,width=400,height=400')

//-->
</script> 
[/HEAD]



Then in your Main page part:

Code:
<%  pagelink = &quot;[URL unfurl="true"]http://www.heinz.com&quot;[/URL] %>    

<a href=&quot;brandserv-list.asp&quot; onclick=&quot;javascript:GoThere('<%=pagelink %>')&quot;> window opener </a>


Or if in a form:

Code:
   <Input type=&quot;Button&quot; Name=&quot;Test&quot; Value=&quot;TestMe&quot; OnClick=&quot;GoThere('<%=pagelink %>')&quot;>

Just an idea..may need work..

[profile]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top