我有这个jquery自动完成工作完美:(比方说,输入文本名称是"项目描述",这些名称来自SQL数据库)
<script>
$(function() {
var availableTags = [
"Apple",
"Banana",
"Mouse"
];
$( "#tags" ).autocomplete({
source: availableTags
});
});
</script>
现在我必须在它旁边添加一个价格输入文本字段。
现在我可以想到的是,填写价格清单(来自SQL数据库)并相应地根据从自动填充字段中选择的项目填写价格。
但是怎么样?有任何想法吗?答案 0 :(得分:0)
$("#Article1C").autocomplete({
source: function( request, response ) {
$.getJSON( "/inc/Autocomplete/ajaxAutocompleteArticle.asp",
{ term: request.term,
rows : 16 },
response );
},
minLength: 2,
select: function( event, ui ) {
if (ui.item) {
$("#ArticleID").val(ui.item.aid);
}
}
});
/inc/Autocomplete/ajaxAutocompleteArticle.asp
类似这样的事情
<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<% Response.ContentType = "text/html; charset=utf-8" %>
<!--#include virtual="/Connections/connection.asp" -->
<%
rsCusts__MMRowsParam = 20: if Request.QueryString("rows") <> "" then rsCusts__MMRowsParam = CLNG(Request.QueryString("rows"))
If (Request.QueryString("term") <> "") Then
rsCusts__MMColParam = Request.QueryString("term")
End If
%>
<%
sOrderrsCusts = " ORDER By Descr1 ASC "
sWherersCusts = " where not costID is null"
sWhere = " AND "
if rsCusts__MMColParam <> "" then
Iterator = split(rsCusts__MMColParam," ")
for i = LBOUND( Iterator ) to UBOUND(Iterator)
k = Instr(Iterator(i),"-")
if k = 1 then
sWherersCusts = sWherersCusts & sWhere & " convert(nvarchar(6),ID) +' '+ Descr1 NOT LIKE '%" & MID(Iterator(i),k+1,LEN(Iterator(i))) & "%'"
else
sWherersCusts = sWherersCusts & sWhere & " convert(nvarchar(6),ID) +' '+ Descr1 LIKE '%" & Iterator(i) & "%'"
end if
sWhere = " AND "
NEXT
else
sWherersCusts = " not costID is null "
end if
%>
<%
Dim rsCusts
Dim rsCusts_cmd
Dim rsCusts_numRows
Set rsCusts_cmd = Server.CreateObject ("ADODB.Command")
rsCusts_cmd.ActiveConnection = MM_connection_STRING
rsCusts_cmd.CommandText = "SELECT TOP "&rsCusts__MMRowsParam&" [ID] ,AID = CostID, ArticleName = convert(nvarchar(6),ID) +' '+ Descr1 FROM [CostItems]" & sWherersCusts & sOrderrsCusts
rsCusts_cmd.CommandType = 1
rsCusts_cmd.Prepared = true
Set rsCusts = rsCusts_cmd.Execute
rsCusts_numRows = 0
%>
<%
Dim Repeat1__numRows
Dim Repeat1__index
Repeat1__numRows = -1
Repeat1__index = 0
rsCusts_numRows = rsCusts_numRows + Repeat1__numRows
Response.Write "["
Comma = ""
While ((Repeat1__numRows <> 0) AND (NOT rsCusts.EOF))
Response.Write Comma & "{""id"":"""&(rsCusts.Fields.Item("ID").Value)&""", ""label"":""" & (rsCusts.Fields.Item("ArticleName").Value)&""", ""value"":""" & (rsCusts.Fields.Item("ID").Value)&""", ""aid"":""" & (rsCusts.Fields.Item("AID").Value)&""" } "
Comma = ","
Repeat1__index=Repeat1__index+1
Repeat1__numRows=Repeat1__numRows-1
rsCusts.MoveNext()
Wend
Response.Write "]"
%>
<%
rsCusts.Close()
Set rsCusts = Nothing
%>