Results 1 to 2 of 2
  1. #1
    Join Date
    Feb 2004
    Posts
    104

    Unanswered: How can I connect the client with server scripts?

    Hi, I am stuck to a very strange problem. I have a .js (javascript) file with some code inside. The file is called from an html file and executed. The result is an inline frame (<iframe>) with some vertical scrolling messages (you know...those that are used to appear news). Inside the file there are the messages in string variables.The javascript code is executed by the client (IE etc.). Ok. The problem is that I do not want every time I need to change the mesages to open the file, change the appropriate sections and upload the updated file. Is there any method to use ASP (or anything else method) to retrieve the text mesages from a database?How can I pass data that come from server side scripting to the client javascript code?

  2. #2
    Join Date
    Mar 2006
    Location
    south jersey, usa
    Posts
    53
    Quote Originally Posted by NonLinear
    Is there any method to use ASP (or anything else method) to retrieve the text mesages from a database?
    open a ado connection to the db, run a query, write the query output

    this code takes a 4 digit input and returns four names.
    Code:
    <html>
    <body OnLoad="document.getcode.agentcode.focus();">
    
    <%
    dim agentcode, puw, cuw, query, rs, conn, routepath, routefile, routename
    dim tries, sqlconn, prt, crt
    
    routepath = "c:\tasks\"
    routename = "actagt2.mdb"
    routefile = routepath & routename
    
    if request.querystring("agentcode") = "" then
      agentcode = "n/a"
    else
      if len(request.querystring("agentcode")) = 4 and isnumeric(request.querystring("agentcode")) then
        agentcode = request.querystring("agentcode")
      else 
        agentcode = "n/a"
        response.write "<font color=red><b>Agent Code must be a four digit number</b></font><br>"
       end if  
    end if
    
    
    set conn = CreateObject("ADODB.Connection")
    set sqlconn = CreateObject("ADODB.Connection")
    set rs = CreateObject("ADODB.Recordset")
    
    tries = 0
    do
      conn.open "DRIVER={Microsoft Access Driver (*.mdb)};" &_
                "DBQ=" & RouteFile & ";DefaultDir=;UID=;PWD=;"
      tries = tries + 1
    Loop While (Err.Number<>0) And tries < 10
    
    sqlconn.open "PROVIDER=SQLOLEDB;DATA SOURCE=imagergt;UID=sa;PWD=xxx;DATABASE=ImgRight"
    
    query = "Select ENDT from MYTABLE where AGENT = '" & agentcode & "01'"
    rs.open query, conn
    if rs.eof then
      if not agentcode = "n/a" then
        response.write "<font color=red><b>Agent Code not found</b></font><br>"
      end if
      puw = "none found"
      prt = puw
      rs.close
    else
      puw = rs(0).value
      rs.close
      query = "Select ENDT from MYTABLE where AGENT = '" & PUW & "'"
      'response.write query
      rs.open query, conn
      if rs.eof then
        prt = "none found"
        rs.close
      else
        prt = rs(0).value
        rs.close
        query = "select username from irsysusers where adjid = '" & prt & "'"
        rs.open query, sqlconn
        prt = rs(0).value
        rs.close
      end if
      query = "select username from irsysusers where adjid = '" & puw & "'"
      rs.open query, sqlconn
      puw = rs(0).value
      rs.close
    end if
    
    query = "Select ENDT from MYTABLE where AGENT = '" & agentcode & "12'"
    rs.open query, conn
    if rs.eof then
      cuw = "none found"
      crt = cuw
      rs.close
    else
      cuw = rs(0).value
      rs.close
      query = "Select ENDT from MYTABLE where AGENT = '" & CUW & "'"
      rs.open query, conn
      if rs.eof then
        crt = "none found"
        rs.close
      else
        crt = rs(0).value
        rs.close
        query = "select username from irsysusers where adjid = '" & crt & "'"
        rs.open query, sqlconn
        crt = rs(0).value
        rs.close
        end if
      query = "select username from irsysusers where adjid = '" & cuw & "'"
      rs.open query, sqlconn
      cuw = rs(0).value
      rs.close
    end if
    
    sqlconn.close
    conn.close
    
    response.write "Agent Code - " & agentcode & "<br>Personal UW - " & puw & "<br>Commerical UW - " & cuw 
    response.write "<br><BR> Personal Rater - " & prt & "<br> Commerical Rater - " & crt %>
    <br><br>
    <form action=" <%= request.servervariables("URL") %>" method="get" name="getcode">
    Enter Agent Code:<br>
    <input type="text" name="agentcode">
    <input type="submit" value="Get UWs & Raters">
    </form>
    </body>
    </html>
    How can I pass data that come from server side scripting to the client javascript code?
    use response.write in server code to write the output that the client receives.

    this code would create a dynamic drop down list

    Code:
    function getuwlist
      query = "Select uw, uwadj from underwriters order by uwadj"
      rs.open query, conn
      if rs.eof then
        getuwlist = "<option>NO UWS FOUND</option>"
        exit function
      else
        do until rs.eof
          getuwlist = getuwlist & "<option>" & rs.fields("uwadj").value & "-" & rs.fields("uw").value & "</option>"
          rs.movenext
        loop
        getuwlist = getuwlist & "</select>"
      end if    
    end function
    "They say Moses split the Red Sea
    I split the blunt and rolled the fat one, I'm deadly"
    -- Tupac 'Blasphemy'

Posting Permissions

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