salve a tutti!
avrei un problema...
leggendo una guida, ho creato il mio box search.
il problema è questo: io vorrei che i risultati della ricerca appaino in un'altra pagina per esempio Search.php
ho provato ad eseguire lo script, ma non funziona
lo script è questo:
Codice PHP:
<script>
function searchPage()
{
var element = document.getElementById('SiteSearch2');
if (element.value.length != 0 || element.value != " ")
{
window.location.href = './Search.php?q='+encodeURIComponent(element.value);
}
return false;
}
</script>
<script>
$(document).ready(function()
{
var $autocomplete = $('<ul class="autocomplete"></ul>').hide().insertAfter('#SiteSearch2');
var selectedItem = null;
var setSelectedItem = function(item)
{
selectedItem = item;
if (selectedItem === null)
{
$autocomplete.hide();
return;
}
if (selectedItem < 0)
{
selectedItem = 0;
}
if (selectedItem >= $autocomplete.find('li').length)
{
selectedItem = $autocomplete.find('li').length - 1;
}
$autocomplete.find('li').removeClass('selected').eq(selectedItem).addClass('selected');
$autocomplete.css('left', $('#SiteSearch2').position().left);
$autocomplete.css('top', $('#SiteSearch2').position().top + $('#SiteSearch2').outerHeight());
$autocomplete.show();
};
var populateSearchField = function()
{
$('#SiteSearch2').val($autocomplete.find('li').eq(selectedItem).text());
setSelectedItem(null);
};
$('#SiteSearch2').attr('autocomplete', 'off').keyup(function(event)
{
if (event.keyCode > 40 || event.keyCode == 8)
{
var data = new Array();
var keywordVal = $('#SiteSearch2').val();
keywordVal = keywordVal.toLowerCase();
for (i=0; i<database_length; i++)
{
var words = (searchDatabase[i].title + " " + searchDatabase[i].description + " " + searchDatabase[i].keywords).toLowerCase();
var array = words.split(" ");
data = $.merge(data, array);
}
var unique = new Array();
o:for(var i = 0; i < data.length; i++)
{
for(var j = 0; j < unique.length; j++)
{
if(unique[j]==data[i]) continue o;
}
unique[unique.length] = data[i];
}
unique.sort();
if (keywordVal.length && unique.length)
{
$autocomplete.empty();
var item = 0;
$.each(unique, function(index, term)
{
term = term.toLowerCase();
if (term.indexOf(keywordVal) == 0)
{
$('<li></li>').text(term).data('item', item).appendTo($autocomplete).mouseover(function()
{
var item = $(this).data('item');
setSelectedItem(item);
}).click(populateSearchField);
item++;
}
});
setSelectedItem(0);
}
else
{
setSelectedItem(null);
}
}
else
if (event.keyCode == 38 && selectedItem !== null)
{
setSelectedItem(selectedItem - 1);
event.preventDefault();
}
else
if (event.keyCode == 40 && selectedItem !== null)
{
setSelectedItem(selectedItem + 1);
event.preventDefault();
}
else
if (event.keyCode == 27 && selectedItem !== null)
{
setSelectedItem(null);
}
}).keypress(function(event)
{
if (event.keyCode == 13 && selectedItem !== null)
{
populateSearchField();
event.preventDefault();
}
}).blur(function(event)
{
setTimeout(function()
{
setSelectedItem(null);
}, 250);
});
});
</script>
cosa devo modificare?