views:

17

answers:

1

Hey, I'm doing a search box and when I want the page to redirect, something strange heppens.

Here is the script:

$('#search_form').submit(function(ev) {
    var searchTerm = $("input[name = search_term]").val();
    var search_location = conf_fullSiteAddress + "search/" + searchTerm + "/";
    alert(search_location);
    window.location.replace( search_location );
});

Now what I want is the user to be redirected to http://www.myaddress/search/searchTerm/.

It is even what I get through the alert(); function, but I get redirected to http://www.myaddress/search// and it totally ignores the searchTerm and it is in the string, because it gets alerted!

Anyone knows what's going on?

Thanks, Mike.

+3  A: 
$('#search_form').submit(function(ev) {

    ev.preventDefault() /* add this */

    var searchTerm = $("input[name = search_term]").val();
    var search_location = conf_fullSiteAddress + "search/" + searchTerm + "/";

    window.location = window.location.replace( search_location ); /* and mod this */
});
meder
Yay, that's it. Thanks.
Mike