He creado un autocomplete con imagenes, lo que quiero hacer es al seleccionar el elemento haga una serie de cosas (habilitar div, guardar su valor,...), pero no consigo hacerlo.
Os pongo el codigo
Busqueda.aspx
Código HTML:
<link href="css/jquery.autocomplete.css" rel="stylesheet" type="text/css" /> <script src="scripts/jquery-1.4.1.min.js" type="text/javascript"></script> <script src="scripts/jquery.autocomplete.js" type="text/javascript"></script> <script type="text/javascript"> $movil = ""; $(document).ready(function () { $("#<%=txtSearch.ClientID%>").autocomplete("Search_VB.ashx", { width: 200, formatItem: function (data, i, n, value) { return "<img style = 'width:25%;height:25%' src='imgmoviles/" + value.split(",")[1] + "'/> " + value.split(",")[0]; }, formatResult: function (data, value) { return value.split(",")[0]; } }); }); </script>
Código:
<%@ WebHandler Language="VB" Class="Search_VB" %> Imports System Imports System.Web Imports MySql.Data Imports MySql.Data.MySqlClient Imports System.Configuration Imports System.Text Public Class Search_VB : Implements IHttpHandler Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest Dim prefixText As String = context.Request.QueryString("q") Dim sql As String sql = "SELECT idMovil,CONCAT(W_Marcas.NombreMarca,' ',W_Moviles.NombreModelo) as Movili,Imagenp" sql = sql + " FROM W_Marcas INNER JOIN" sql = sql + " W_Moviles ON W_Marcas.IdMarca = W_Moviles.IdMarca" sql = sql + " WHERE CONCAT(W_Marcas.NombreMarca,' ',W_Moviles.NombreModelo) LIKE '" & "%" & Trim(prefixText) & "%'" sql = sql + " AND W_Moviles.NombreModelo is not null" sql = sql + " ORDER BY W_Marcas.NombreMarca,W_Moviles.NombreModelo" Dim conn As MySqlConnection = New MySqlConnection conn.ConnectionString = ConfigurationManager _ .ConnectionStrings("Conex").ConnectionString Dim cmd As MySqlCommand = New MySqlCommand cmd.CommandText = sql cmd.Connection = conn Dim sb As StringBuilder = New StringBuilder conn.Open() Dim sdr As MySqlDataReader = cmd.ExecuteReader While sdr.Read sb.Append(String.Format("{0},{1}{2}", sdr("Movili"), sdr("Imagenp"), Environment.NewLine)) End While conn.Close() context.Response.Write(sb.ToString) End Sub Public ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable Get Return False End Get End Property End Class