Q:

jQuery text input validate against ASP Recordset

Not sure if it's possible to update this jQuery to validate against an ASP populated array.
Below I validate against MIDlist in my jQuery, but now I want to validate against an ASP populated array.
My original validation list is as follows; 
var MIDlist = ['12345','90210','12346','12347'];
Using a populated array created from the asp connection below, I want to replace ['12345','90210','12346','12347'] with a data list from my MSSQL database.
var MIDlist = ['12345','90210','12346','12347'];
function validateMID() {
      return $.inArray($('#MID').val(), MIDlist) > -1;
      //true means the MID is in the list, false it is not
}

$(function() { // Shorthand for $(document).ready(function() {
      $('#MID').keyup(function() {
          if( $('#MID').val().length == 5 ) {              
            if (!validateMID()) {
                  // Good, MID is allowed
                  $('#MID').removeClass('red');
                  $('p').text('MID does not exist.');
            } else {
                  // MID already exist
                  $('#MID').addClass('red');
                  $('p').text('MID was found in the list! Do not use.');
            }
         }
      });
});

This is the ASP select statement that I want to now validate against.
<%
Dim MID_LIST
Dim MID_LIST_cmd
Dim MID_LIST_numRows

Set MID_LIST_cmd = Server.CreateObject ("ADODB.Command")
MID_LIST_cmd.ActiveConnection = MM_ServerConnection_STRING
MID_LIST_cmd.CommandText = "SELECT MID FROM dbo.tblCustomer WHERE intActiveStatus = 1 and intCancelled = 0 and intMarkAsRemovedFlag = 0" 
MID_LIST_cmd.Prepared = true

Set MID_LIST = MID_LIST_cmd.Execute
MID_LIST_numRows = 0
%>

So how do I modify the above ASP code to create a populated array and have the jQuery read the array?
Thanks, Ray.

A:

First of all - I presume you understand that your jQuery code is client side and your ASP VBScript code is server side.  This means that the jQuery code can't see the VBScript, only the output.
What I assume you want to do is replace your line
var MIDlist = ['12345','90210','12346','12347'];

with an array populated by Classic asp code
<%
'First of all you open a connection to the database

dim conn
set conn = Server.Createobject("ADODB.Connection")
conn.Open MM_ServerConnection_STRING

'Then create a recordset object

dim rs
set rs = Server.CreateObject("ADODB.Recordset")

'And a database query to populate the recordset

dim query
query = "SELECT MID FROM dbo.tblCustomer WHERE intActiveStatus = 1 and intCancelled = 0 and intMarkAsRemovedFlag = 0"

'open your recordset

rs.open query,conn

'and loop through it to build the array you want to use in your jQuery code

dim myJqueryArray
myJqueryArray = ""
Do until rs.eof
    myJqueryArray = myJqueryArray & "'" & rs("MID") & "'"
rs.movenext
    myJqueryArray = myJqueryArray & ","
loop

'tidy up
set rs = nothing
set conn = nothing
%>

Note that the comma is inserted after the movenext instruction, this prevents a comma being added after the final value in the array.
Once you've done this you can replace the first line of your jQuery code with 
var MIDlist = [<%= myJqueryArray %>];

Creating a recordset is a common task in Classic ASP, you should find plenty of tutorials on how to do it on the internet.  I recommend that you do, rather than generating code with Dreamweaver which is very bloated and difficult to understand.

