View Single Post
  #27 (permalink)  
Old May 8th, 2008, 09:40 PM
gok gok is offline
Registered User
 
Join Date: May 2008
Location: , , .
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hello, Joe.
After couple of hours playing with code this version works as expected:
Code:
<%@ LANGUAGE=JavaScript %>
<HTML><HEAD><TITLE>dbTest</TITLE>
<%
        // this part is running on Server side
Response.Write("<script type='text/javascript'>\n");
    var conn = Server.CreateObject("ADODB.Connection");
    var strConn = "Provider=SQLOLEDB.1;Data source=amsql;Database=pubs;Trusted_Connection=no;User ID=guest;Password=password;"
    conn.Open(strConn);
    var rs = conn.Execute("SELECT * FROM STORES");
    var i = 0;
    // store recs to the client
    Response.Write("var names=[");
    while (!rs.EOF)
    {
        if ( i++>0 ) Response.Write(",");
        var name = rs.fields("stor_name").value.toString();
        name = name.replace(/(^\s*)|(\s*$)/g, ""); // trim spaces
        Response.Write("\"" + name + "\"");
        rs.MoveNext();
    }
    Response.Write("];\n");
        rs.Close();
    conn.Close();
Response.Write("</script>");
%>
<script type='text/javascript'>
    // this part is running on Client side
    function addNames()
    {
          var list = document.getElementById("quickZoom");
          for (var i = 0, l = names.length; i < l; i++)
          {
            var oOption = new Option(names[i], names[i]);
            list.options.add(oOption);
          }
    }
</script>
</HEAD>

<BODY onload="addNames()">
Store Names:<br>
<select id="lstNames" name="quickZoom"></select>
</BODY>
</HTML>
Thanks a lot for you patience and for sharing your knowledge!
Happy programming!
Gennady

Reply With Quote