根据ASP记录集验证jQuery文本输入
不确定是否可以更新此jQuery以针对ASP填充的数组进行验证 下面我在jQuery中根据中间列表进行验证,但现在我想根据ASP填充的数组进行验证 我的原始验证清单如下: var MIDlist=['12345'、'90210'、'12346'、'12347'] 使用从下面的asp连接创建的填充数组,我想用MSSQL数据库中的数据列表替换['12345'、'90210'、'12346'、'12347']根据ASP记录集验证jQuery文本输入,jquery,sql-server,asp-classic,Jquery,Sql Server,Asp Classic,不确定是否可以更新此jQuery以针对ASP填充的数组进行验证 下面我在jQuery中根据中间列表进行验证,但现在我想根据ASP填充的数组进行验证 我的原始验证清单如下: var MIDlist=['12345'、'90210'、'12346'、'12347'] 使用从下面的asp连接创建的填充数组,我想用MSSQL数据库中的数据列表替换['12345'、'90210'、'12346'、'12347'] var MIDlist = ['12345','90210','12346','12347'
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.');
}
}
});
});
这是我现在要验证的ASP select语句
<%
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
%>
那么,如何修改上面的ASP代码来创建一个填充的数组,并让jQuery读取该数组呢
谢谢,Ray。首先,我想您应该了解jQuery代码是客户端的,而ASP VBScript代码是服务器端的。这意味着jQuery代码不能看到VBScript,只能看到输出 我想你要做的是更换你的线路
var MIDlist = ['12345','90210','12346','12347'];
使用由经典asp代码填充的数组
<%
'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
%>
请注意,逗号插入到movenext指令之后,这将防止在数组中的最终值之后添加逗号
完成此操作后,可以将jQuery代码的第一行替换为
var MIDlist = [<%= myJqueryArray %>];
var MIDlist=[];
创建记录集是经典ASP中的一项常见任务,您应该可以找到大量有关如何在internet上创建记录集的教程。我建议您这样做,而不是使用Dreamweaver生成代码,因为Dreamweaver非常臃肿且难以理解。今天我将尝试一下。谢谢你在这件事上的帮助。是的,我真的应该远离Dreamweaver学习代码。再次感谢。工作做得很好!谢谢你,约翰。