Results 1 to 4 of 4

Thread: ASP

  1. #1
    2 Star Lounger
    Join Date
    Mar 2002
    Posts
    164
    Thanks
    0
    Thanked 0 Times in 0 Posts

    ASP

    I'm trying to replace an included .js script with an asp page. Below is the original .js file...

    var messages=new Array()
    messages[0]="<font face='Verdana, MS Sans Serif, Geneva' size='-2'>To order your Abstract Book or CD-ROM please visit our Purchase Abstract/CD</font>"
    messages[1]="<font face='Verdana, MS Sans Serif, Geneva' size='-2'>We have a new URL. Please update your bookmarks.</font>"
    messages[2]="<font face='Verdana, MS Sans Serif, Geneva' size='-2'>2003 Fuel Cell Seminar will take place in Miami Beach, Nov. 3-6</font>"

    Now my asp page is like so...
    <%
    Dim mySQL, myRS
    mySQL = "SELECT n_desc FROM News"
    Set myRS = myConn.Execute(mySQL)
    While Not myRS.EOF
    Response.Write myRS("n_desc") & ""
    myRS.MoveNext
    Wend
    %>

    I need to somehow write out the messages[]=" stuff. Any clue how to accomplish this with ASP. Thanks beforehand!!

  2. #2
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: ASP

    ASP is VBScript (usually), which uses this convention:

    Response.Write "Have a ""nice"" day." & vbCrLf

    to render

    Have a "nice" day.

    on its own line.

    If you write your ASP page in JavaScript, I think you would use the " (escaped ") to insert the literals. (But I haven't tried it.)

  3. #3
    2 Star Lounger
    Join Date
    Mar 2002
    Posts
    164
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: ASP

    Is it possible to combine these somehow?

    <%
    Dim messageindex
    messageindex = 0
    Do until rs.EOF
    %>
    messages[<%=messageindex%>]="<font face='Verdana, MS Sans Serif, Geneva' size='-2'><%=rs("Message")%></font>"
    <%
    messageindex= messageindex +1
    rs.Movenext
    Loop %>


    <%
    Dim mySQL, myRS
    mySQL = "SELECT n_desc FROM News"
    Set myRS = myConn.Execute(mySQL)
    While Not myRS.EOF
    Response.Write myRS("n_desc") & ""
    myRS.MoveNext
    Wend
    %>

  4. #4
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: ASP

    Close! Combining looks like this:

    <%
    Response.Write "<script>" & vbCrLf & "var messages=new Array()" & vbCrLf
    Dim mySQL, myRS, messageindex
    messageindex = 0
    mySQL = "SELECT n_desc FROM News"
    Set myRS = myConn.Execute(mySQL)
    While Not myRS.EOF
    Response.Write "messages[" & messageindex & "]=""<font face='Verdana, MS Sans Serif, Geneva' size='-2'>" & _
    myRS("n_desc") & </font>""" & vbCrLf
    messageindex = messageindex + 1
    myRS.MoveNext
    Wend
    Response.Write "</script>" & vbCrLf
    %>

    As you can see, you are using ASP to literally transcribe the script tag contents letter by letter. This is more efficient than jumping back and forth between ASP and HTML, although it does cause those annoying error message when you forget to double some quotation marks or to continue a line... does this help?

Posting Permissions

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