Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 12 of 12

Thread: JS and ASP

  1. #1
    Regular Coder
    Join Date
    Jan 2003
    Posts
    148
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question JS and ASP

    I wonder if I can put any ASP within an javascript something like:

    var marqueecontent='<nobr><%

    Response.write("<font-family: Arial Narrow; font-size: 8pt>" )
    Set conn = server.createobject("adodb.connection")
    dbName="deneme.mdb"
    connect ="provider=microsoft.jet.oledb.4.0;data source="
    connect=connect & server.mappath(dbName)& ";"
    conn.open connect


    decribing the content dynamically by getting the data from the database?

  • #2
    Senior Coder
    Join Date
    Jun 2002
    Location
    41° 8' 52" N -95° 53' 31" W
    Posts
    3,660
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Sure, I do it all the time. Of course, you have to insert the database info into your JavaScript on the server-side.

    Former ASP Forum Moderator - I'm back!

    If you can teach yourself how to learn, you can learn anything. ;)

  • #3
    Regular Coder
    Join Date
    Jan 2003
    Posts
    148
    Thanks
    0
    Thanked 0 Times in 0 Posts
    hmmm that's good news but I think I need more explanation then that.

    Actually I wanna do this text scroller dynamically and it's where I am still working on. So basically the javascript is consists of

    describing the variables first and then using these variables in functions.

    so it was the decribing the marquee's content where I used ASP to call the content from the database with the code I had shown in the previous message.

    Is that enough or do I need to indicate that in the functions where it needs the marquee content? What I was thinking is that once the content is described it can be used in the functions without calling it from the database again.

    Am I in the wrong direction?

  • #4
    Senior Coder
    Join Date
    Jun 2002
    Location
    41° 8' 52" N -95° 53' 31" W
    Posts
    3,660
    Thanks
    0
    Thanked 0 Times in 0 Posts
    No, you're on the right path. Just transfer all of your database information into corresponding arrays or whatever in javascript.

    Easiest way to figure it out is just to try it! Mess with some simple code first, like this:

    Code:
    <%@ Page Language="VBScript" %>
    <%
    Dim mystring
    mystring = "Yay, this works!"
    ' This is an example
    %>
    <html>
       <head>
          <title></title>
       </head>
       <body>
          <script type="text/javascript">
          <!--
          alert('<% = mystring %>');
          // -->
          </script>
       </body>
    </html>
    Then move on to inserting stuff in an array, etc. If you have a problem, then your best bet to fix syntax errors in THIS case would be to view the source of the HTML that is sent to the client-side, so you can see what you're putting into the javascript...
    Former ASP Forum Moderator - I'm back!

    If you can teach yourself how to learn, you can learn anything. ;)

  • #5
    Regular Coder
    Join Date
    Jan 2003
    Posts
    148
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Thumbs up

    excellent it works with mystring bit now I'll try to replace it with the actual ASP code which will retrieve from the database.

    I wonder if I can use:

    set content = "SELECT * from News"

    as an SQL statement in my ASP code.

    Thanks very much

  • #6
    Senior Coder
    Join Date
    Jun 2002
    Location
    41° 8' 52" N -95° 53' 31" W
    Posts
    3,660
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Like I said, don't wonder... try it out!

    If it doesn't work, then view the source code to see what errors are being generated.

    I've been programming for only about 2 years, and I've learned that probably the most important thing that a programmer needs to learn is how to research things (even by doing a google search!), and more importantly, just to keep experimenting with code to see if it works. You learn a lot that way.

    Not to mention... that's what really makes programming fun, at least to me. Once you get something working, you have learned quite a few things. They all add up, too. Programming is one field that gives you a great sense of accomplishment.

    Last edited by whammy; 02-20-2003 at 02:15 AM.
    Former ASP Forum Moderator - I'm back!

    If you can teach yourself how to learn, you can learn anything. ;)

  • #7
    Regular Coder
    Join Date
    Jan 2003
    Posts
    148
    Thanks
    0
    Thanked 0 Times in 0 Posts
    ok i won't wonder any more

    i am trying to see what happens...

    cheers

  • #8
    Senior Coder
    Join Date
    Jun 2002
    Location
    41° 8' 52" N -95° 53' 31" W
    Posts
    3,660
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Cheers to you too... now remember, if you're having specific problems with your syntax, or problems with a concept, don't forget to post here.

    But the main thing I was trying to get across is not to ask questions like "will this work?", since the best way to find out whether something works or not is to try it first.
    Former ASP Forum Moderator - I'm back!

    If you can teach yourself how to learn, you can learn anything. ;)

  • #9
    Regular Coder
    Join Date
    Jan 2003
    Posts
    148
    Thanks
    0
    Thanked 0 Times in 0 Posts
    well unfortunately I have tried few things and I couldn't work it out where I am doing the mistake. I have defined the ASP part as :

    <%

    Dim oConn
    Dim oRS
    Dim sSQL

    Set oConn = Server.CreateObject("ADODB.Connection")
    oConn.Open("DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("\anticus\db\deneme.mdb"))

    sSQL = "SELECT * from Branch where Branch_Code='Bristol' "
    Set oRS = oConn.Execute(sSQL)

    oConn.Close
    Set oRS = Nothing
    Set oConn = Nothing

    %>


    and I have used :

    1) <%Response.Write( & oRS("Branch_Code").Value &)%> where it gave error about & things

    2) < % = oRS("Branch_Code") %> where it didn't work

    I couldn't work it out in both cases and I dunno which syntax I have to use in my javascript to display the result of my SQL statement I have included at the top

  • #10
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,075
    Thanks
    0
    Thanked 256 Times in 252 Posts
    that's because you closed the recordset and connection objects just after you created them and before you tried to retrieve of the fields in the database. Plus you have syntax errors.

    <%
    Dim oConn
    Dim oRS
    Dim sSQL

    Set oConn = Server.CreateObject("ADODB.Connection")
    oConn.Open("DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("\anticus\db\deneme.mdb"))

    sSQL = "SELECT * from Branch where Branch_Code='Bristol' "
    Set oRS = oConn.Execute(sSQL)
    %>

    <script language="javascript">
    var branchCode = "<%=oRS("Branch_Code")%>";
    alert(branchCode);
    </script>

    <%
    oRS.close
    oConn.Close
    Set oRS = Nothing
    Set oConn = Nothing

    %>
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________

  • #11
    Regular Coder
    Join Date
    Jan 2003
    Posts
    148
    Thanks
    0
    Thanked 0 Times in 0 Posts
    i was thinking of using the javascript in the body part of my code. In that case I won't be able to close the oRS in the body part.

    In the previous code the retrieving part of ASP was in head part and the javascript is in the body part so how can I close that in body part of the code?

    Thanks

  • #12
    Senior Coder
    Join Date
    Jun 2002
    Location
    Zwolle, The Netherlands
    Posts
    1,120
    Thanks
    2
    Thanked 31 Times in 31 Posts
    you can close it where ever you want to close it after use, you can even do:

    </body>
    <%
    oRS.close
    oConn.Close
    Set oRS = Nothing
    Set oConn = Nothing
    %>

    remember, the output of the asp code's response.write's appear in the html code which is sent to the browser. if you have asp-code, which doesnt produce html output, it can be put at the end of the file, or whereever you want to put it.
    I am the luckiest man in the world


  •  

    Posting Permissions

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