Combining Two Javascript And JQuery Scripts
I have two seperate Javascript/jQuery scripts which I would like to combine. One is a tabbed search box script which determines the destination of the form when it is submitted. Th
Solution 1:
You can get the selected tab from Tabs.types.selected
and know it on your query. For example
$(document).ready(function(){
$("#query").keyup(function(e){
if(e.keyCode==13){
var query=$(this).val();
var yt_url='search.php?tab=' + Tabs.types.selected + '&q=' + encodeURIComponent(query);
window.location.hash='search/'+query+'/';
$.ajax({
type:"GET",
url:yt_url,
dataType:"html",
success:function(results){
$('#results').html(results);
}
});
}
});
});
I suggest to encode your query with encodeURIComponent
, or else if your user type & and ? and other symbols, then never reach your page as parametres.
Also place the var Tabs = { search: { ..etc
before this code so you are sure that the Tabs are found.
Post a Comment for "Combining Two Javascript And JQuery Scripts"