jQuery 文本输入根据 ASP 记录集进行验证
jQuery text input validate against ASP Recordset
不确定是否可以更新此 jQuery 以根据 ASP 填充数组进行验证。
下面我在 jQuery 中针对 MIDlist 进行验证,但现在我想针对 ASP 填充的数组进行验证。
我原来的验证列表如下;
var MIDlist = ['12345','90210','12346','12347'];
使用从下面的 asp 连接创建的填充数组,我想用我的 MSSQL 数据库中的数据列表替换 ['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 读取该数组?
谢谢,雷。
首先 - 我假设您了解您的 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 %>];
创建记录集是 Classic ASP 中的一项常见任务,您应该可以在 Internet 上找到大量有关如何执行此操作的教程。我建议您这样做,而不是使用非常臃肿且难以理解的 Dreamweaver 生成代码。
不确定是否可以更新此 jQuery 以根据 ASP 填充数组进行验证。
下面我在 jQuery 中针对 MIDlist 进行验证,但现在我想针对 ASP 填充的数组进行验证。
我原来的验证列表如下;
var MIDlist = ['12345','90210','12346','12347'];
使用从下面的 asp 连接创建的填充数组,我想用我的 MSSQL 数据库中的数据列表替换 ['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 读取该数组?
谢谢,雷。
首先 - 我假设您了解您的 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 %>];
创建记录集是 Classic ASP 中的一项常见任务,您应该可以在 Internet 上找到大量有关如何执行此操作的教程。我建议您这样做,而不是使用非常臃肿且难以理解的 Dreamweaver 生成代码。