Hello all i want to append parameter to url if and only if search text box value is different than default. Actually i have 3 search text boxes and i want to append them to url
here is my code..
$("#search-btn").click(function (e) {
e.preventDefault();
var search_country = $("#search-country").val();
var search_city = $("#search-city").val();
var search_team = $("#search-team").val();
var dataString = 'action=search'
// var dataString = {
// action : 'search',
// param1 : $("#search-country").val() || '',
// param2 : $("#search-city").val() || '',
// param3 : $("#search-team").val() || ''
// };
if (search_country != "Search by Country") {
dataString = dataString + "¶m1=" + search_country
}
if (search_city != "Search by City") {
dataString = dataString + "¶m2=" + search_city
}
if (search_team != "Search by team") {
dataString = dataString + "¶m3=" + search_team
}
$.ajax({
type: "get",
url: "SearchServlet",
data: dataString,
success: function (data) {
$('body').html(data);
$('#msg').html('Search Results')
}
});
});
I want to pass parameter only if user enter search criteria otherwise not....