SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast
    Join Date
    Jan 2002
    Location
    New Zealand
    Posts
    45
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    passing asp variable to js file

    Hi,

    I have an asp variable <%=stylesheet%> (which translates to styleblue.css) etc which I need to pass to a js file ->

    <script language="JavaScript" src="include/calender.js"></script>

    and then include the variable in this section of the code ->

    var str_buffer = new String (
    "<html>\n"+
    "<head>\n"+
    "<title>Calendar</title>\n"+
    "<LINK REL=\"StyleSheet\" HREF=\"include/simple.css\" type=\"text/css\">\n"+
    "</head>\n"+

    I guess conceptually I need to do something along these lines ->

    <script language="JavaScript" src="include/calender.js?SS="&stylesheet></script>


    var stylesheet = stylesheet
    var str_buffer = new String (
    "<html>\n"+
    "<head>\n"+
    "<title>Calendar</title>\n"+
    "<LINK REL=\"StyleSheet\" HREF=\"" + stylesheet + "\" type=\"text/css\">\n"+
    "</head>\n"+

    but can't figure out how - have followed a number of threads/searches.

    Any help much appreciated.
    Last edited by JessieMc; Feb 9, 2002 at 10:36.
    JessieMc

  2. #2
    I have an opinion...
    Join Date
    Sep 2001
    Location
    Barrie, Ontario
    Posts
    324
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Is there a particular reason you are wanting to use a querystring? If you simply set the variable in your header before you include the JS file, any function in the JS file can access the variable.

    Code:
    <%
    	Response.Write( "<script language=" & Chr(34) & "javascript & Chr(34) & ">" & vbCrLf & vbTab & "var strStyle = " & _
    		            Chr(39) & strStyleSheet & Chr(39) & Chr(59) & vbCrlf & "</script>" & vbCrLf )
    %>
    <script language="JavaScript" src="include/calender.js"></script>
    Your calendar.js functions will be able to retrieve the value of the strStyle variable that is set before the file is included.

    Is this what you need?
    Egotist: A person more interested in himself than in me.
    KodeKrash - Eidix - Barrie LUG

  3. #3
    SitePoint Enthusiast
    Join Date
    Jan 2002
    Location
    New Zealand
    Posts
    45
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    thanks

    Thanks for putting me on track KodeKrash yes this works just fine.

    <script language="JavaScript">var strStyle="<%=Stylesheet%>"</script>

    then in js file

    var str_buffer = new String (
    "<html>\n"+
    "<head>\n"+
    "<title>Calendar</title>\n"+
    "<LINK REL=\"StyleSheet\" HREF=\""+strStyle+"\" type=\"text/css\">\n"+
    "</head>\n"+
    JessieMc


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •