List Info

Thread: Using AutoComplete Widget for Navigation




Using AutoComplete Widget for Navigation
country flaguser name
United States
2008-03-28 11:34:50

Currently using an AutoComplete instance to create a search feature
for an ecommerce site. The data source is a MySQL database containing
product names, descriptions, and URLs. So far so good. The data
source is returning the product name and URL, and the name gets
displayed in the AutoComplete text box. The name is linked to the URL
so that if you click the product name, you get taken to the product's
page on the site.

myAutoComp.formatResult = function(aResultItem, sQuery)
{
var myURL = aResultItem[1];
var myText = aResultItem[0];
if (myURL == "NOURL")
{
var sMarkup = myText;
}
else
{
var sMarkup = '<a href=";' + myURL + '">;' + myText
+ '</a>;';
}
return (sMarkup);
}

The problem is that this works great for mouse clicks, but not for
anyone who uses the Enter key. Additionally only the product name is
actually a live link whereas it would be preferable for the whole
<li&gt; element to be linked. Any clues on resolving these problems
please?

__._,_.___
.

__,_._,___
Re: Using AutoComplete Widget for Navigation
country flaguser name
United States
2008-03-28 14:37:54

Hi,

On Fri, Mar 28, 2008 at 5:34 PM, aqhost < aqhost%40yahoo.com">aqhostyahoo.com> wrote:
&gt; The name is linked to the URL
> so that if you click the product name, you get taken to the product's
> page on the site.
&gt;
> myAutoComp.formatResult = function(aResultItem, sQuery)
> {
> var myURL = aResultItem[1];
&gt; var myText = aResultItem[0];
&gt; if (myURL == "NOURL")
> {
> var sMarkup = myText;
> }
> else
>; {
> var sMarkup = '<a href=";' + myURL + '">;' + myText
&gt; + '</a>;';
> }
> return (sMarkup);
> }
>
> The problem is that this works great for mouse clicks, but not for
> anyone who uses the Enter key. Additionally only the product name is
> actually a live link whereas it would be preferable for the whole
&gt; <li> element to be linked. Any clues on resolving these problems
> please?

Try using the itemSelectEvent[1] provided by the AutoComplete class instead:

myAutoComp.itemSelectEvent.subscribe(function (eventType, eventArgs) {
var item = eventArgs[2];
var url = item[1];
if (url !== "NOURL") {
window.location.href = url;
}
});

Regards,

[1] http://developer.yahoo.com/yui/docs/YAHOO.widget.AutoComplete.html#event_itemSelectEvent

--
Fiouz

__._,_.___
.

__,_._,___
[1-2]

about | contact  Other archives ( Real Estate discussion Medical topics )